Professional Documents
Culture Documents
1 Objective-C
Robert Chi
contact@robertchi.tw
Objective-C
Xcode
Objective-C
Hello! World!
Objective-C Programming 1
Objective-C
Objective-C Programming 1
1986
Tom Love
Objective-C Programming 1
Brad Cox
NeXT
Steve Jobs
Objective-C Programming 1
Java
1986
Objective-C Programming 1
1995
Apple NeXT
Objective-C Programming 1
iOS
Objective-C Programming 1
Xcode
Objective-C Programming 1
XCode
IDE, Integrated Developing Environment
o Objective-C, C/C++, Java
Objective-C Programming 1
10
XCode
Developer
US$ 99.00
Objective-C Programming 1
11
Objective-C Programming 1
12
XCode
Objective-C Programming 1
13
Objective-C Programming 1
14
XCode
Objective-C Programming 1
15
Objective-C Programming 1
16
Lab 01-01
Xcode
o Xcode
Objective-C Programming 1
17
Objective-C
Objective-C Programming 1
18
Xcode
Objective-C Programming 1
19
Objective-C Programming 1
20
Objective-C Programming 1
21
(Toolbar)
(File Browser
Panel)
Objective-C Programming 1
(Edit Panel)
22
File Browser
o
Source:
Documentation:
External Frameworks:
Products:
o Smart Groups
Targets:
Executables:
Find Results:
Bookmarks:
SCM (Software Configuration
Management):
Subversion
Objective-C Programming 1
23
Objective-C Programming 1
24
(1) (2)
1.
2.
3.
4.
5.
Objective-C Programming 1
(3)
(4) (5)
KB
25
1.
2.
3.
4.
5.
6.
7.
Objective-C Programming 1
26
Objective-C Programming 1
27
Objective-C Programming 1
28
Run Console Command + Shift + R
Debug Information
Objective-C Programming 1
29
Lab 01-02
Objective-C
o Xcode Xcode
o 01-01-FirstProgram
Mac OS XApplication
Command Line Tool
TypeFoundation
o 01-02-FirstProgram.m
o
Command + Shift + R Debugger Console
Build and Run
Objective-C Programming 1
30
Hello! World!
Objective-C Programming 1
31
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
Objective-C Programming 1
32
#import
Header Files
o #import <>
#import <Foundation/Foundation.h>
o #import
#import my_header.h
Objective-C Cocoa
o Foundation: UI
#import <Foundation/Foundation.h>
o Application Kit (AppKit, UIKit): UI
#import <UIKit/UIKit.h>
Objective-C Programming 1
33
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here
o
o
//
//
/*
*/
/* /**/*/
Objective-C Programming 1
34
1.
2.
o
o
int argc:
const char* argv[]: const
3.
o int: 0
Objective-C Programming 1
35
Cocoa
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[pool drain];
return 0;
}
o Cocoa Foundation, AppKit
o
o Cocoa NSAutoreleasePool
o [[NSAutoreleasePool alloc] init] C++ NSAutoreleasePool.alloc().init();
o [pool drain] C++ pool.drain();
Objective-C Programming 1
36
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
NSLog(...) log
o 2011-07-13 08:33:08.917 01-01-FirstProgram[1440:903] Hello, World!
@Hello, World!
o @ NSString
o C
NS NeXTStep NeXT
Objective-C Programming 1
37
NSLog(...)
o NSString
o \n NSLog()
NSLog(Hello! \n World!\n);
o %i
NSLog(The value of i = %i\n, i);
printf()
o
o Objective-C @ NSString
o NSLog printf()
Objective-C Programming 1
38
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
Objective-C C
o 0
o Error Code
Objective-C Programming 1
39
o
o
o
o
o
o
#import
Objective-C
NSAutoreleasePool
NSLog()
0
Objective-C Programming 1
40
Xcode
Hello! World!
Objective-C Programming 1
41
Objective-C Programming 1
42