Close button event on OS X app swift 2.2

Update for Swift 4.1:

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    NSApplication.shared.terminate(self)
    return true
}

func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool {
    NSApplication.sharedApplication().terminate(self)
    return true
}

Inside appdeligate work for me.

For Swift 4.2

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    NSApplication.shared.terminate(self)
    return true
}

Tags:

Macos

Cocoa

Swift