Instance Method


Invoked when the user closes the last window the application has open.


optional func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool



The application object whose last window was closed.

Return Value

false if the application should not be terminated when its last window is closed; otherwise, true to terminate the application.


The application sends this message to your delegate when the application’s last window is closed. It sends this message regardless of whether there are still panels open. (A panel in this case is defined as being an instance of NSPanel or one of its subclasses.)

If your implementation returns false, control returns to the main event loop and the application is not terminated. If you return true, your delegate’s applicationShouldTerminate(_:) method is subsequently invoked to confirm that the application should be terminated.

See Also

Terminating Applications

func applicationShouldTerminate(NSApplication) -> NSApplication.TerminateReply

Sent to notify the delegate that the application is about to terminate.

func applicationWillTerminate(Notification)

Sent by the default notification center immediately before the application terminates.

enum NSApplication.TerminateReply

Constants used by the delegate method applicationShouldTerminate(_:) to determine whether an app should terminate.