How to make a Cocoa application quit when the main window is closed? Without that you have to click on the app icon and click quit in the menu.
As the question is mainly about Cocoa programming and not about a specific language (Objective-C), here is the Swift version of Chuck's and Steve's answer:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool {
return true
}
// Your other application delegate methods ...
}
For Swift 3 change the method definition to
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}