Protocol

NSApplicationDelegate

A set of methods that delegates of NSApplication objects can implement.

Declaration

protocol NSApplicationDelegate

Topics

Launching Applications

func applicationWillFinishLaunching(Notification)

Sent by the default notification center immediately before the application object is initialized.

func applicationDidFinishLaunching(Notification)

Sent by the default notification center after the application has been launched and initialized but before it has received its first event.

NSApplicationDidFinishLaunching User Info Keys

The following constants define the keys that can be present in the didFinishLaunchingNotification.

Managing Active Status

func applicationWillBecomeActive(Notification)

Sent by the default notification center immediately before the application becomes active.

func applicationDidBecomeActive(Notification)

Sent by the default notification center immediately after the application becomes active.

func applicationWillResignActive(Notification)

Sent by the default notification center immediately before the application is deactivated.

func applicationDidResignActive(Notification)

Sent by the default notification center immediately after the application is deactivated.

Terminating Applications

func applicationShouldTerminate(NSApplication) -> NSApplication.TerminateReply

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

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.

Hiding Applications

func applicationWillHide(Notification)

Sent by the default notification center immediately before the application is hidden.

func applicationDidHide(Notification)

Sent by the default notification center immediately after the application is hidden.

func applicationWillUnhide(Notification)

Sent by the default notification center immediately after the application is unhidden.

func applicationDidUnhide(Notification)

Sent by the default notification center immediately after the application is made visible.

Managing Windows

func applicationWillUpdate(Notification)

Sent by the default notification center immediately before the application object updates its windows.

func applicationDidUpdate(Notification)

Sent by the default notification center immediately after the application object updates its windows.

func applicationShouldHandleReopen(NSApplication, hasVisibleWindows: Bool) -> Bool

Sent by the application to the delegate prior to default behavior to reopen (rapp) AppleEvents.

Managing the Dock Menu

func applicationDockMenu(NSApplication) -> NSMenu?

Allows the delegate to supply a dock menu for the application dynamically.

Displaying Errors

func application(NSApplication, willPresentError: Error) -> Error

Sent to the delegate before the specified application presents an error message to the user.

Managing the Screen

func applicationDidChangeScreenParameters(Notification)

Sent by the default notification center when the configuration of the displays attached to the computer is changed (either programmatically or when the user changes settings in the Displays control panel).

Continuing User Activities

func application(NSApplication, willContinueUserActivityWithType: String) -> Bool

Tells the delegate the user wants to continue an activity in your app.

func application(NSApplication, didUpdate: NSUserActivity)

Tells the delegate that the user activity object has been updated.

Handling Push Notifications

func application(NSApplication, didRegisterForRemoteNotificationsWithDeviceToken: Data)

Sent to the delegate when Apple Push Services successfully completes the registration process.

func application(NSApplication, didFailToRegisterForRemoteNotificationsWithError: Error)

Sent to the delegate when Apple Push Service cannot successfully complete the registration process.

func application(NSApplication, didReceiveRemoteNotification: [String : Any])

Sent to the delegate when a running application receives a remote notification.

Handling CloudKit Invitations

func application(NSApplication, userDidAcceptCloudKitShareWith: CKShareMetadata)

Tells the delegate that the user accepted a CloudKit sharing invitation associated with your app.

Opening Files

func application(NSApplication, openFile: String) -> Bool

Tells the delegate to open a single file.

func application(Any, openFileWithoutUI: String) -> Bool

Tells the delegate to open a file programmatically.

func application(NSApplication, openTempFile: String) -> Bool

Tells the delegate to open a temporary file.

func application(NSApplication, openFiles: [String])

Tells the delegate to open multiple files.

func applicationOpenUntitledFile(NSApplication) -> Bool

Tells the delegate to open an untitled file.

func applicationShouldOpenUntitledFile(NSApplication) -> Bool

Invoked immediately before opening an untitled file.

Restoring Application State

func application(NSApplication, didDecodeRestorableState: NSCoder)

Tells the delegate the application has extracted its restorable state from a given archiver.

func application(NSApplication, willEncodeRestorableState: NSCoder)

Tells the delegate the application will encode any application state that was preserved between application launches.

Handling Changes to the Occlusion State

func applicationDidChangeOcclusionState(Notification)

Tells the delegate the application’s occlusion state changed.

Relationships

Inherits From

See Also

Application

class NSApplication

An object that manages an app’s main event loop and resources used by all of that app’s objects.

class NSRunningApplication

An object that can manipulate and provide information for a single instance of an app.