Objective-C + Cocoa on the Command Line
Sometimes there’s just one tiny snippet of Cocoa code that you want to test — maybe to find out the output of NSDateFormatter for various cases, testing out some text replacement routine, or testing out some image drawing code.
It’s often too much trouble to create a new XCode project and set up the framework to do one simple test, which is why I put together this little shell script that lets you run Cocoa code from the command line:
$ runcocoa 'NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"d MMM, h:mm a"]; NSLog(@"%@", [formatter stringFromDate:[NSDate date]]);'
2011-02-23 20:02:10.313 runcocoa-output[28025:903] 23 Feb, 8:02 PM
You have full access to all Cocoa libraries, and in iOS mode, access to most iOS stuff too, straight from the command line.
Update: This is now available as a [GitHub project](https://github.com/michaeltyson/Commandline-Cocoa)
Read More