如何在Terminal命令行模式下运行Objective-C

一般Objective-C的代码都在Xcode中调试,今天实验了下如何在命令行模式下运行,还是比较简单的,记录分享一下。

File: xxd.h

#include <Foundation/Foundation.h>

@interface Xxd: NSObject

{

}

- (void) xxdSayHelloTo: (NSString *)name;

@end

 

File: xxd.m

#include <Foundation/Foundation.h>
#include "xxd.h"

@implementation Xxd

- (void) xxdSayHelloTo: (NSString *)name

{

NSLog(@"Hello World, %@", name);

}

@end

File: main.m

#include <Foundation/Foundation.h>

#include “xxd.h”

int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

id speaker;   

NSString *name = @"buro79xxd";   

xxd = [[Xxd alloc] init];   

[xxd xxdSayHelloTo:name];   

[xxd release];   

[pool drain];   

return 0;   

}


屏幕快照 2012-06-07 上午9.30.28.png

运行一下:

xuexiaodong79 at Air in ~

$ gcc -framework Foundation main.m xxd.m -o xxd

xuexiaodong79 at Air in ~

$ ./xxd

2012-06-07 09:28:40.815 xxd[1459:707] Hello World, buro79xxd

屏幕快照 2012-06-07 上午9.30.53.png

posted @ 2012-06-07 09:32  xxd  阅读(...)  评论(...编辑  收藏