• Save
OOP: Chapter 2: Programming in Objective-C
Upcoming SlideShare
Loading in...5
×
 

OOP: Chapter 2: Programming in Objective-C

on

  • 1,225 views

http://www.youtube.com/watch?v=loLa1cZosvg

http://www.youtube.com/watch?v=loLa1cZosvg

Statistics

Views

Total Views
1,225
Views on SlideShare
1,041
Embed Views
184

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 184

http://www.atit.patumvan.com 184

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

OOP: Chapter 2: Programming in Objective-C OOP: Chapter 2: Programming in Objective-C Presentation Transcript

  • Object-Oriented Programming Language Chapter 2 : Programming in Objective-C Atit Patumvan Faculty of Management and Information Sciences Naresuna Universityวันอังคารที่ 7 กุมภาพันธ์ 12
  • 2 Program 2.1 (ex02-01.m) // First program example #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! NSLog (@"Programming is fun"); ! ! [pool drain]; ! return 0; } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 3 Compile and Running Program • OSX gcc -framework Foundation hello.m -o hello • Windows: GNUStep: gcc gcc `gnustep-config --objc-flags` -L /GNUstep/System/ Library/Libraries hello.m -o hello -lgnustep-base -lobjc • Linux gcc `gnustep-config --objc-flags` hello.m -o hello -I / usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep- base Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 4 Common Filename Extension Extension Meaning .c C language source file .cc, .cpp C++ language source file .h Header file .m Objective-C source file .mm Objective-C++ source file .pl Perl source file .o Object (compiled) file Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 5 Explanation of Your First Program // First program example #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! NSLog (@"Programming is fun"); ! ! [pool drain]; ! return 0; } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 6 Program 2.2 (ex02-02.m) #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! ! NSLog (@"Programming is fun"); ! NSLog (@"Programming in Objective-C is event more fun!"); ! ! [pool drain]; ! return 0; } Programming is fun Programming in Objective-C is event more fun! Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 7 Program 2.3 (ex02-03.m) #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! ! NSLog (@"Testing...n..1n...2n....3"); ! ! [pool drain]; ! return 0; } Testing... ..1 ...2 ....3 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 8 Program 2.4 (ex02-04.m) #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! ! int sum; ! ! sum = 50 + 25; ! NSLog (@"The sum of 50 and 25 is %i", sum); ! ! [pool drain]; ! ! return 0; } The sum of 50 and 25 is 75 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12
  • 9 Program 2.5 (ex02-05.m) #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { ! NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ! ! int value1, value2, sum; ! ! value1 = 50; ! value2 = 25; ! sum = value1 + value2; ! NSLog (@"The sum of %i and %i is %i", value1, value2, sum); ! ! [pool drain]; ! ! return 0; } The sum of 50 and 25 is 75 Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Languageวันอังคารที่ 7 กุมภาพันธ์ 12