Hi All, Recently, I was writing a command-line tool and I didn't feel like dropping down to printf() for console output, so I wrote this category.
Drop this in your project… > @interface NSString (console) > > - (void) writeToFileHandle:(NSFileHandle *) handle; > - (void) writeToStdOut; > - (void) writeToStdErr; > > @end > > @implementation NSString (console) > > - (void) writeToFileHandle:(NSFileHandle *) handle { [handle writeData:[self > dataUsingEncoding:NSUTF8StringEncoding]]; } > - (void) writeToStdOut { [self writeToFileHandle:[NSFileHandle > fileHandleWithStandardOutput]]; } > - (void) writeToStdErr { [self writeToFileHandle:[NSFileHandle > fileHandleWithStandardError]]; } > > @end …and you'll be able to tell strings to output themselves like so: [@"Hello, World!\n" writeToStdOut]; [@"Oh, no! Something broke!\n" writeToStdErr]; [[self description] writeToStdOut]; -jcr_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com