Command line tool in Objective-C using Foundation?
is there a simple way to create a command-line tool in Objective C?
I'd rather not use XCode, because XCode has targets and executables, and just complicated stuff.
I'd like to go classic way, just create a Makefile, compile something get an executable, play with it.
--
If this is not possible, is there any way to run the executable I get from regular XCode CL projec开发者_开发技巧t? It creates a build and again - complicated stuff.
I just want to use my terminal instead of XCode's Console.
Yes. Just write your files as normal Objective-C files and compile with GCC or Clang, linking in the Foundation framework. It's hardly different from a normal C program.
Simple example:
chuck$ cat > main.m
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *words = [NSArray arrayWithObjects:@"Hello,", @"world!", @"Check", @"this", @"out!", nil];
NSLog(@"%@", [words componentsJoinedByString:@" "]);
[pool release];
return 0;
}
chuck$ cc -framework Foundation -o my-app main.m
chuck$ ./my-app
2010-10-26 22:32:04.652 my-app[5049:903] Hello, world! Check this out!
精彩评论