I'm not sure which is the right way, right now I'm just calling exit(0)
when a user clicks on the exit button.
How to properly quit application, call exit(0)?
Asked Answered
Don't forget to title your button “Quit”, not “Exit”. –
Vas
Use NSApplication
's terminate
method. For example:
[NSApp terminate:self]
Documentation is available here.
The previously given answer is deprecated since 10.10 and this question is the first thing that turns up for cocoa quit application, so use this instead (Swift):
NSApplication.sharedApplication().terminate(self)
Note: As of now it's the following:
NSApplication.shared().terminate(self)
What's deprecated? The use of
NSApp
? NSApp
still appears to be available and isn't marked as deprecated in the documentation… –
Bifocals Because I just had to do this again: the original way to do it now yields:
static member 'sharedApplication' cannot be used on instance of type 'NSApplication'
. PS: Note that I wrote the comment above when Swift was still quite unstable, and especially Xcode was quirky as hell. So the error message might have been different at the time. –
Shanklin I always terminate App the safe way.
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
This will put the event in the next loop.
© 2022 - 2024 — McMap. All rights reserved.