Instance Method

applicationShouldTerminate(_:)

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

Declaration

optional func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply

Parameters

sender

The application object that is about to be terminated.

Return Value

One of the values defined in NSApplication.TerminateReply constants indicating whether the application should terminate. For compatibility reasons, a return value of false is equivalent to NSApplication.TerminateReply.terminateCancel, and a return value of true is equivalent to NSApplication.TerminateReply.terminateNow.

Discussion

This method is called after the application’s Quit menu item has been selected, or after the terminate(_:) method has been called. Generally, you should return NSApplication.TerminateReply.terminateNow to allow the termination to complete, but you can cancel the termination process or delay it somewhat as needed. For example, you might delay termination to finish processing some critical data but then terminate the application as soon as you are done by calling the reply(toApplicationShouldTerminate:) method.

See Also

Terminating Applications

func applicationShouldTerminateAfterLastWindowClosed(NSApplication) -> Bool

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

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.