Home

NSPrincipalClass

NSPrincipalClass is a key in a macOS application's Info.plist that designates the class to instantiate as the app’s principal NSApplication object when the application launches. If the key is not present, the system uses the default NSApplication class.

At startup, the application’s main entry point (such as NSApplicationMain) reads the Info.plist and creates an

To use NSPrincipalClass, you create a subclass of NSApplication in your project and specify its class name

Notes and considerations: the custom principal class must be available at launch time and correctly linked

instance
of
the
class
named
by
NSPrincipalClass
to
serve
as
the
shared
application
object.
This
principal
class
can
be
a
subclass
of
NSApplication,
and
it
provides
a
place
to
customize
the
application’s
event
loop
and
global
behavior
by
overriding
NSApplication
methods.
as
the
value
of
the
NSPrincipalClass
key
in
Info.plist.
In
Swift,
the
value
may
need
to
include
the
module
name
(for
example,
MyModule.MyApplication)
depending
on
your
project
setup.
In
Objective-C,
the
plain
class
name
is
typically
sufficient.
The
subclass
can
override
methods
such
as
-sendEvent:,
-finishLaunching:,
or
other
NSApplication
lifecycle
methods
to
implement
app-wide
behavior.
Even
with
a
custom
principal
class,
you
can
still
employ
an
NSApplicationDelegate
to
handle
most
application
lifecycle
events.
to
the
target.
NSPrincipalClass
is
specific
to
macOS
Cocoa
apps
and
is
not
used
in
iOS,
where
UIApplicationMain
handles
application
initialization.