How can I tell my Cocoa application to quit from within the application itself?

后端 未结 1 1369
再見小時候
再見小時候 2021-01-31 15:46

I\'m looking for a good way to tell my Cocoa application to quit itself. Rest assured that this will not be used for production code. I\'m just looking for an easy way to run on

相关标签:
1条回答
  • 2021-01-31 16:32

    You can pretty much rest assured that your app is going to get killed at least some of the time. Thus, defending against exits the like of exit(0); is required.

    However, NSApplication implements the -terminate: method.

    [NSApp terminate: nil]; ought to do what you want.

    I would generally suggest posting it via -performSelector:afterDelay: with a delay of 0.0 to force it to happen at the top of the next pass through the event loop.

    Example:

    [NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
    
    0 讨论(0)
提交回复
热议问题