Any good way to set the exit status of a Cocoa application?

Posted by buglesareking on Stack Overflow See other posts from Stack Overflow or by buglesareking
Published on 2010-04-30T03:31:52Z Indexed on 2010/04/30 3:37 UTC
Read the original article Hit count: 233

Filed under:
|
|

I have a Cocoa app which interacts with a server and displays a GUI. If there is a fatal error, I display an alert and exit. I'd like to set the exit status to a non-zero value to reflect that an error occurred, for ease of interaction with some other UNIX based tools.

Unfortunately I've been unable to find a good way to do so - NSApplication doesn't seem to have any way to set an exit status. At the moment, I've subclassed NSApplication and added an exitStatus ivar (which I set in my app delegate when necessary), then overridden -terminate: so that it calls exit(exitStatus). This works fine, but it seems a bit grungy to me, not to mention that I may be missing something important that the stadnard `terminate: is doing behind the scenes. I can't call [super terminate:sender] in my subclassed method, because that exit()s without giving me a chance to set the status.

Am I missing something obvious?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa