OOP: Chapter 2: Programming in Objective-C

1,068 views
990 views

Published on

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

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,068
On SlideShare
0
From Embeds
0
Number of Embeds
185
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

OOP: Chapter 2: Programming in Objective-C

  1. 1. Object-Oriented Programming Language Chapter 2 : Programming in Objective-C Atit Patumvan Faculty of Management and Information Sciences Naresuna Universityวันอังคารที่ 7 กุมภาพันธ์ 12
  2. 2. 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. 3. 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. 4. 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. 5. 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. 6. 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. 7. 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. 8. 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. 9. 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

×