01
#import <Foundation/Foundation.h>
02
03
int
main
(
int
argc
,
const
char
*
argv
[])
04
{
05
NSAutoreleasePool
*
pool
=
[[
NSAutoreleasePool
alloc
]
init
];
06
07
NSLog
(
@"Programming is fun!"
);
08
NSLog
(
@"Programming in Objective-C is even more fun!"
);
09
10
[
pool
drain
];
11
return
0
;
12
}
02
03
04
05
06
07
08
09
10
11
12
注意:新手比较容易遇到一个问题就是每个Objective-C程序语句必须使用分号结束。
输出的结果如下:
Programming is fun!
Programming in Objective-C is even more fun!
接下来是范例2-3 在Objective-C中使用
换行符(反斜杠\和字母n)来实现多行文字输出
01 #import <Foundation/Foundation.h>
02
03 int main (int argc, const char * argv[])
04 {
05 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06
07 NSLog(@"Testing...\n..1\n...2\n....3");
08 [pool drain];
09 return 0;
10 }
02
03
04
05
06
07
08
09
10
输出的结果如下: