Last Updated: February 25, 2016
·
5.209K
· maxehmookau

Output an NSString to STDOUT in Objective-C

Admittedly, this is something you wouldn't often want to do unless writing an command line application in Objective-C/Cocoa, but writing to STDOUT instead of using

NSLog(@"%@", object);

Means that the response can be used by piping to pbcopy for example. So do this instead:

[aString writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:nil];

And then your string will output to stdout instead of just posting a console log.

1 Response
Add your response

it works but it seems weird! nice to know how NSLog output things

over 1 year ago ·