Home

NSApplicationDelegate

NSApplicationDelegate is a protocol in the AppKit framework that defines the delegate interface for NSApplication objects. An object that conforms to the protocol can receive messages about the application's lifecycle and other high-level events, enabling centralized control of app behavior without subclassing NSApplication. The NSApplicationDelegate protocol is part of the Cocoa application architecture; its methods are optional, so a delegate implements only the events it needs.

Common methods include applicationDidFinishLaunching, invoked when the app has completed its launch; applicationWillTerminate, called just before

In practice, the delegate is typically implemented by an AppDelegate class that conforms to NSApplicationDelegate and

The concept complements the NSApplication and the broader AppKit lifecycle, and is a common component in macOS

the
app
terminates;
and
applicationShouldTerminate,
which
asks
the
delegate
to
decide
whether
the
app
should
quit,
allowing
cleanup
or
cancellation.
There
are
also
callbacks
for
the
app
becoming
active
or
resigning
active,
and
for
various
state
transitions
during
startup
and
termination.
is
assigned
to
NSApp.delegate.
In
Swift,
the
AppDelegate
implements
the
protocol
and
provides
implementations
for
the
selected
methods.
The
delegate
pattern
allows
the
application
to
initialize
resources,
restore
state,
save
data,
and
handle
termination
in
a
centralized,
platform-consistent
way.
applications
developed
with
Cocoa.