Objective-c – Completely close an OS X application with window close button

macosobjective cxcode

I need completely close my application when a user closes the document window using the applications at runtime.

Currently when they click the window, the application stays open and is displaying its menu bar. I read this article for iOS and to add an entry into the plist file:
http://developer.appcelerator.com/question/40081/ios4—make-app-not-run-in-background

What is the easiest way for me to close the entire app when a user closes the document window?

Best Answer

Is this a Mac app? If so, have your NSApp delegate implement applicationShouldTerminateAfterLastWindowClosed::

- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)application
{
    return YES;
}

Using Swift, it would be:

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
     return true
}
Related Topic