Mac Developer Library — Prerelease

Developer

AppKit Framework Reference NSApplication Class Reference

Options
Deployment Target:

On This Page
Language:

NSApplication

Class at a Glance

An NSApplication object manages an app’s main event loop in addition to resources used by all of that app’s objects.

The NSApplication class provides the central framework for your app’s execution.

Every app must have exactly one instance of NSApplication (or a subclass of NSApplication). Your program’s main() function should create this instance by invoking the sharedApplication class method. After creating the NSApplication object, the main() function should load your app’s main nib file and then start the event loop by sending the NSApplication object a run message. If you create an Application project in Xcode, this main() function is created for you. The main() function Xcode creates begins by calling a function named NSApplicationMain(), which is functionally similar to the following:

  1. void NSApplicationMain(int argc, char *argv[]) {
  2. [NSApplication sharedApplication];
  3. [NSBundle loadNibNamed:@"myMain" owner:NSApp];
  4. [NSApp run];
  5. }

The sharedApplication class method initializes the display environment and connects your program to the window server and the display server. The NSApplication object maintains a list of all the NSWindow objects the app uses, so it can retrieve any of the app’s NSView objects. The sharedApplication method also initializes the global variable NSApp, which you use to retrieve the NSApplication instance. sharedApplication only performs the initialization once; if you invoke it more than once, it simply returns the NSApplication object it created previously.

The shared NSApplication object performs the important task of receiving events from the window server and distributing them to the proper NSResponder objects. NSApp translates an event into an NSEvent object, then forwards the NSEvent object to the affected NSWindow object. All keyboard and mouse events go directly to the NSWindow object associated with the event. The only exception to this rule is if the Command key is pressed when a key-down event occurs; in this case, every NSWindow object has an opportunity to respond to the event. When an NSWindow object receives an NSEvent object from NSApp, it distributes it to the objects in its view hierarchy.

NSApplication is also responsible for dispatching certain Apple events received by the app. For example, OS X sends Apple events to your app at various times, such as when the app is launched or reopened. NSApplication installs Apple event handlers to handle these events by sending a message to the appropriate object. You can also use the NSAppleEventManager class to register your own Apple event handlers. The applicationWillFinishLaunching: method is generally the best place to do so. For more information on how events are handled and how you can modify the default behavior, including information on working with Apple events in scriptable apps, see How Cocoa Applications Handle Apple Events in Cocoa Scripting Guide.

The NSApplication class sets up @autorelease block during initialization and inside the event loop—specifically, within its initialization (or sharedApplication) and run methods. Similarly, the methods AppKit adds to NSBundle employ @autorelease blocks during the loading of nib files. These @autorelease blocks aren’t accessible outside the scope of the respective NSApplication and NSBundle methods. Typically, an app creates objects either while the event loop is running or by loading objects from nib files, so this lack of access usually isn’t a problem. However, if you do need to use Cocoa classes within the main() function itself (other than to load nib files or to instantiate NSApplication), you should create an @autorelease block to contain the code using the classes.

The Delegate and Notifications

You can assign a delegate to NSApp. The delegate responds to certain messages on behalf of NSApp. Some of these messages, such as application:openFile:, ask the delegate to perform an action. Another message, applicationShouldTerminate:, lets the delegate determine whether the app should be allowed to quit. The NSApplication class sends these messages directly to its delegate.

The NSApp also posts notifications to the app’s default notification center. Any object may register to receive one or more of the notifications posted by NSApp by sending the message addObserver:selector:name:object: to the default notification center (an instance of the NSNotificationCenter class). The delegate of NSApp is automatically registered to receive these notifications if it implements certain delegate methods. For example, NSApp posts notifications when it is about to be done launching the app and when it is done launching the app (NSApplicationWillFinishLaunchingNotification and NSApplicationDidFinishLaunchingNotification). The delegate has an opportunity to respond to these notifications by implementing the methods applicationWillFinishLaunching: and applicationDidFinishLaunching:. If the delegate wants to be informed of both events, it implements both methods. If it needs to know only when the app is finished launching, it implements only applicationDidFinishLaunching:.

System Services

NSApplication interacts with the system services architecture to provide services to your app through the Services menu.

Subclassing Notes

You rarely should find a real need to create a custom NSApplication subclass. Unlike some object-oriented libraries, Cocoa does not require you to subclass NSApplication to customize app behavior. Instead it gives you many other ways to customize an app. This section discusses both some of the possible reasons to subclass NSApplication and some of the reasons not to subclass NSApplication.

To use a custom subclass of NSApplication, simply send sharedApplication to your subclass rather than directly to NSApplication. If you create your app in Xcode, you can accomplish this by setting your custom app class to be the principal class. In Xcode, double-click the app target in the Groups and Files list to open the Info window for the target. Then display the Properties pane of the window and replace “NSApplication” in the Principal Class field with the name of your custom class. The NSApplicationMain function sends sharedApplication to the principal class to obtain the global app instance (NSApp)—which in this case will be an instance of your custom subclass of NSApplication.

Methods to Override

Generally, you subclass NSApplication to provide your own special responses to messages that are routinely sent to the global app object (NSApp). NSApplication does not have primitive methods in the sense of methods that you must override in your subclass. Here are four methods that are possible candidates for overriding:

  • Override run if you want the app to manage the main event loop differently than it does by default. (This a critical and complex task, however, that you should only attempt with good reason.)

  • Override sendEvent: if you want to change how events are dispatched or perform some special event processing.

  • Override requestUserAttention: if you want to modify how your app attracts the attention of the user (for example, offering an alternative to the bouncing app icon in the Dock).

  • Override targetForAction: to substitute another object for the target of an action message.

Special Considerations

The global app object uses @autorelease blocks in its run method; if you override this method, you’ll need to create your own @autorelease blocks.

Do not override sharedApplication. The default implementation, which is essential to app behavior, is too complex to duplicate on your own.

Alternatives to Subclassing

NSApplication defines numerous delegate methods that offer opportunities for modifying specific aspects of app behavior. Instead of making a custom subclass of NSApplication, your app delegate may be able to implement one or more of these methods to accomplish your design goals. In general, a better design than subclassing NSApplication is to put the code that expresses your app’s special behavior into one or more custom objects called controllers. Methods defined in your controllers can be invoked from a small dispatcher object without being closely tied to the global app object.

  • Returns the application instance, creating it if it doesn’t exist yet.

    Declaration

    Swift

    class func sharedApplication() -> NSApplication

    Objective-C

    + (__kindof NSApplication * _Nonnull)sharedApplication

    Return Value

    The shared application object.

    Discussion

    This method also makes a connection to the window server and completes other initialization. Your program should invoke this method as one of the first statements in main(); this invoking is done for you if you create your application with Xcode. To retrieve the NSApplication instance after it has been created, use the global variable NSApp or invoke this method.

    Availability

    Available in OS X v10.0 and later.

  • Activates the app, opens any files specified by the NSOpen user default, and unhighlights the app’s icon.

    Declaration

    Swift

    func finishLaunching()

    Objective-C

    - (void)finishLaunching

    Discussion

    The run method calls this method before it starts the event loop. When this method begins, it posts an NSApplicationWillFinishLaunchingNotification to the default notification center. If you override finishLaunching, the subclass method should invoke the superclass method.

    Availability

    Available in OS X v10.0 and later.

    See Also

    applicationWillFinishLaunching: (NSApplicationDelegate)
    applicationDidFinishLaunching: (NSApplicationDelegate)

  • The app delegate object.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSApplicationDelegate?

    Objective-C

    @property(assign, nullable) id< NSApplicationDelegate > delegate

    Discussion

    The app object and app delegate work in tandem to manage the app’s overall behavior. Typically, the delegate is configured automatically by the Xcode project templates.

    Availability

    Available in OS X v10.0 and later.

  • The image used for the app’s icon.

    Declaration

    Swift

    var applicationIconImage: NSImage!

    Objective-C

    @property(strong) NSImage * _Null_unspecified applicationIconImage

    Discussion

    Assign an image to this property when you want to temporarily change the app icon in the dock app tile. The image you provide is scaled as needed so that it fits in the tile. To restore your app’s original icon, set this property to nil.

    Availability

    Available in OS X v10.0 and later.

  • Terminates the receiver.

    Declaration

    Swift

    func terminate(_ sender: AnyObject?)

    Objective-C

    - (void)terminate:(id _Nullable)sender

    Parameters

    sender

    Typically, this parameter contains the object that initiated the termination request.

    Discussion

    This method is typically invoked when the user chooses Quit or Exit from the app’s menu.

    When invoked, this method performs several steps to process the termination request. First, it asks the app’s document controller (if one exists) to save any unsaved changes in its documents. During this process, the document controller can cancel termination in response to input from the user. If the document controller does not cancel the operation, this method then calls the delegate’s applicationShouldTerminate: method. If applicationShouldTerminate: returns NSTerminateCancel, the termination process is aborted and control is handed back to the main event loop. If the method returns NSTerminateLater, the app runs its run loop in the NSModalPanelRunLoopMode mode until the replyToApplicationShouldTerminate: method is called with the value YEStrue or NOfalse. If the applicationShouldTerminate: method returns NSTerminateNow, this method posts a NSApplicationWillTerminateNotification notification to the default notification center.

    Do not bother to put final cleanup code in your app’s main() function—it will never be executed. If cleanup is necessary, perform that cleanup in the delegate’s applicationWillTerminate: method.

    Availability

    Available in OS X v10.0 and later.

  • Responds to NSTerminateLater once the app knows whether it can terminate.

    Declaration

    Swift

    func replyToApplicationShouldTerminate(_ shouldTerminate: Bool)

    Objective-C

    - (void)replyToApplicationShouldTerminate:(BOOL)shouldTerminate

    Parameters

    shouldTerminate

    Specify YEStrue if you want the app to terminate; otherwise, specify NOfalse.

    Discussion

    If your app delegate returns NSTerminateLater from its applicationShouldTerminate: method, your code must subsequently call this method to let the NSApplication object know whether it can actually terminate itself.

    Availability

    Available in OS X v10.0 and later.

  • The last event object that the app retrieved from the event queue. (read-only)

    Declaration

    Swift

    var currentEvent: NSEvent? { get }

    Objective-C

    @property(readonly, strong, nullable) NSEvent *currentEvent

    Discussion

    The shared app object receives events and forwards them to the affected NSWindow objects, which then distribute them to the objects in its view hierarchy. Use this property to get the event that was last handled by the app.

    Availability

    Available in OS X v10.0 and later.

  • Returns the next event matching a given mask, or nil if no such event is found before a specified expiration date.

    Declaration

    Swift

    func nextEventMatchingMask(_ mask: Int, untilDate expiration: NSDate?, inMode mode: String, dequeue deqFlag: Bool) -> NSEvent?

    Objective-C

    - (NSEvent * _Nullable)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate * _Nullable)expiration inMode:(NSString * _Nonnull)mode dequeue:(BOOL)flag

    Parameters

    mask

    Contains one or more flags indicating the types of events to return. The constants section of the NSEvent class defines the constants you can add together to create this mask. The discardEventsMatchingMask:beforeEvent: method also lists several of these constants.

    expiration

    The expiration date for the current event request. Specifying nil for this parameter is equivalent to returning a date object using the distantPast method.

    mode

    The run loop mode in which to run while looking for events. The mode you specify also determines which timers and run-loop observers may fire while the app waits for the event.

    flag

    Specify YEStrue if you want the event removed from the queue.

    Return Value

    The event object whose type matches one of the event types specified by the mask parameter.

    Discussion

    You can use this method to short circuit normal event dispatching and get your own events. For example, you may want to do this in response to a mouse-down event in order to track the mouse while its button is down. (In such an example, you would pass the appropriate event types for mouse-dragged and mouse-up events to the mask parameter and specify the NSEventTrackingRunLoopMode run loop mode.) Events that do not match one of the specified event types are left in the queue.

    You can specify one of the run loop modes defined by AppKit or a custom run loop mode used specifically by your app. AppKit defines the following run-loop modes:

    • NSDefaultRunLoopMode

    • NSEventTrackingRunLoopMode

    • NSModalPanelRunLoopMode

    • NSConnectionReplyMode

    Availability

    Available in OS X v10.0 and later.

  • Removes all events matching the given mask and generated before the specified event.

    Declaration

    Swift

    func discardEventsMatchingMask(_ mask: Int, beforeEvent lastEvent: NSEvent?)

    Objective-C

    - (void)discardEventsMatchingMask:(NSUInteger)mask beforeEvent:(NSEvent * _Nullable)lastEvent

    Parameters

    mask

    Contains one or more flags indicating the types of events to discard. The constants section of the NSEvent class defines the constants you can add together to create this mask. The discussion section also lists some of the constants that are typically used.

    lastEvent

    A marker event that you use to indicate which events should be discarded. Events that occurred before this event are discarded but those that occurred after it are not.

    Discussion

    Use this method to ignore any events that occurred before a specific event. For example, suppose your app has a tracking loop that you exit when the user releases the mouse button. You could use this method, specifying NSAnyEventMask as the mask argument and the ending mouse-up event as the lastEvent argument, to discard all events that occurred while you were tracking mouse movements in your loop. Passing the mouse-up event as lastEvent ensures that any events that might have occurred after the mouse-up event (that is, that appear in the queue after the mouse-up event) are not discarded.

    For the mask parameter, you can add together event type constants such as the following:

    • NSLeftMouseDownMask

    • NSLeftMouseUpMask

    • NSRightMouseDownMask

    • NSRightMouseUpMask

    • NSMouseMovedMask

    • NSLeftMouseDraggedMask

    • NSRightMouseDraggedMask

    • NSMouseEnteredMask

    • NSMouseExitedMask

    • NSKeyDownMask

    • NSKeyUpMask

    • NSFlagsChangedMask

    • NSPeriodicMask

    • NSCursorUpdateMask

    • NSAnyEventMask

    This method can also be called in subthreads. Events posted in subthreads bubble up in the main thread event queue.

    Availability

    Available in OS X v10.0 and later.

  • A Boolean value indicating whether the main event loop is running. (read-only)

    Declaration

    Swift

    var running: Bool { get }

    Objective-C

    @property(getter=isRunning, readonly) BOOL running

    Discussion

    The value of this property is YEStrue when the main event loop is running or NOfalse when it is not. Calling the stop: method sets the value to NOfalse.

    Availability

    Available in OS X v10.10 and later.

  • Starts the main event loop.

    Declaration

    Swift

    func run()

    Objective-C

    - (void)run

    Discussion

    The loop continues until a stop: or terminate: message is received. Upon each iteration through the loop, the next available event from the window server is stored and then dispatched by sending it to NSApp using sendEvent:.

    After creating the NSApplication object, the main function should load your app’s main nib file and then start the event loop by sending the NSApplication object a run message. If you create an Cocoa app project in Xcode, this main function is implemented for you.

    Availability

    Available in OS X v10.0 and later.

  • Stops the main event loop.

    Declaration

    Swift

    func stop(_ sender: AnyObject?)

    Objective-C

    - (void)stop:(id _Nullable)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This method notifies the app that you want to exit the current run loop as soon as it finishes processing the current NSEvent object. This method does not forcibly exit the current run loop. Instead it sets a flag that the app checks only after it finishes dispatching an actual event object. For example, you could call this method from an action method responding to a button click or from one of the many methods defined by the NSResponder class. However, calling this method from a timer or run-loop observer routine would not stop the run loop because they do not result in the posting of an NSEvent object.

    If you call this method from an event handler running in your main run loop, the app object exits out of the run method, thereby returning control to the main() function. If you call this method from within a modal event loop, it will exit the modal loop instead of the main event loop.

    Availability

    Available in OS X v10.0 and later.

  • Dispatches an event to other objects.

    Declaration

    Swift

    func sendEvent(_ theEvent: NSEvent)

    Objective-C

    - (void)sendEvent:(NSEvent * _Nonnull)anEvent

    Parameters

    anEvent

    The event object to dispatch.

    Discussion

    You rarely invoke sendEvent: directly, although you might want to override this method to perform some action on every event. sendEvent: messages are sent from the main event loop (the run method). sendEvent: is the method that dispatches events to the appropriate responders—NSApp handles app events, the NSWindow object indicated in the event record handles window-related events, and mouse and key events are forwarded to the appropriate NSWindow object for further dispatching.

    Availability

    Available in OS X v10.0 and later.

  • Adds a given event to the receiver’s event queue.

    Declaration

    Swift

    func postEvent(_ event: NSEvent, atStart flag: Bool)

    Objective-C

    - (void)postEvent:(NSEvent * _Nonnull)anEvent atStart:(BOOL)flag

    Parameters

    anEvent

    The event object to post to the queue.

    flag

    Specify YEStrue to add the event to the front of the queue; otherwise, specify NOfalse to add the event to the back of the queue.

    Discussion

    This method can also be called in subthreads. Events posted in subthreads bubble up in the main thread event queue.

    Availability

    Available in OS X v10.0 and later.

  • Starts a modal event loop for a given window.

    Declaration

    Swift

    func runModalForWindow(_ theWindow: NSWindow) -> Int

    Objective-C

    - (NSInteger)runModalForWindow:(NSWindow * _Nonnull)aWindow

    Parameters

    aWindow

    The window to be displayed modally. If it is not already visible, the window is centered on the screen using the value in its centermethod and made visible and key. If it is already visible, it is simply made key.

    Return Value

    An integer indicating the reason that this method returned. See NSModalResponse possible return values.

    Discussion

    This method runs a modal event loop for the specified window synchronously. It displays the specified window, makes it key, starts the run loop, and processes events for that window. (You do not need to show the window yourself.) While the app is in that loop, it does not respond to any other events (including mouse, keyboard, or window-close events) unless they are associated with the window. It also does not perform any tasks (such as firing timers) that are not associated with the modal run loop. In other words, this method consumes only enough CPU time to process events and dispatch them to the action methods associated with the modal window.

    You can exit the modal loop by calling the stopModal, stopModalWithCode:, or abortModal methods from your modal window code. If you use the stopModalWithCode: method to stop the modal event loop, this method returns the argument passed to stopModalWithCode:. If you use stopModal instead, this method returns the constant NSModalResponseStop. If you use abortModal, this method returns the constant NSModalResponseAbort.

    Availability

    Available in OS X v10.0 and later.

  • Stops a modal event loop.

    Declaration

    Swift

    func stopModal()

    Objective-C

    - (void)stopModal

    Discussion

    This method should always be paired with a previous invocation of runModalForWindow: or beginModalSessionForWindow:. When runModalForWindow: is stopped with this method, it returns NSModalResponseStop. This method stops the loop only if it’s executed by code responding to an event. If you need to stop a runModalForWindow: loop outside of one of its event callbacks (for example, a method repeatedly invoked by an NSTimer object or a method running in a different thread), use the abortModal method.

    Availability

    Available in OS X v10.0 and later.

  • Stops a modal event loop, allowing you to return a custom result code.

    Declaration

    Swift

    func stopModalWithCode(_ returnCode: Int)

    Objective-C

    - (void)stopModalWithCode:(NSInteger)returnCode

    Parameters

    returnCode

    The result code you want returned from the runModalForWindow: or runModalSession: method. The meaning of this result code is up to you.

    Discussion

    This method should always be paired with a previous invocation of runModalForWindow: or beginModalSessionForWindow:. When runModalForWindow: is stopped with this method, it returns the given returnCode. This method stops the loop only if it’s executed by code responding to an event. If you need to stop a runModalForWindow: loop outside of one of its event callbacks (for example, a method repeatedly invoked by an NSTimer object or a method running in a different thread), use the abortModal method.

    Availability

    Available in OS X v10.0 and later.

  • Aborts the event loop started by runModalForWindow: or runModalSession:.

    Declaration

    Swift

    func abortModal()

    Objective-C

    - (void)abortModal

    Discussion

    When stopped with this method, runModalForWindow: and runModalSession: return NSModalResponseAbort.

    abortModal must be used instead of stopModal or stopModalWithCode: when you need to stop a modal event loop from anywhere other than a callout from that event loop. In other words, if you want to stop the loop in response to a user’s actions within the modal window, use stopModal; otherwise, use abortModal. For example, use abortModal when running in a different thread from AppKit’s main thread or when responding to an NSTimer that you have added to the NSModalPanelRunLoopMode mode of the default NSRunLoop.

    Availability

    Available in OS X v10.0 and later.

  • Sets up a modal session with the given window and returns an NSModalSession structure representing the session.

    Declaration

    Swift

    func beginModalSessionForWindow(_ theWindow: NSWindow) -> NSModalSession

    Objective-C

    - (NSModalSession _Nonnull)beginModalSessionForWindow:(NSWindow * _Nonnull)aWindow

    Parameters

    aWindow

    The window for the session.

    Return Value

    The NSModalSession structure that represents the session.

    Discussion

    In a modal session, the app receives mouse events only if they occur in aWindow. The window is made key, and if not already visible is placed onscreen using the NSWindow method center.

    The beginModalSessionForWindow: method only sets up the modal session. To actually run the session, use runModalSession:. beginModalSessionForWindow: should be balanced by endModalSession:. Make sure these two messages are sent within the same exception-handling scope. That is, if you send beginModalSessionForWindow: inside an NS_DURING construct, you must send endModalSession: before NS_ENDHANDLER.

    If an exception is raised, beginModalSessionForWindow: arranges for proper cleanup. Do not use NS_DURING constructs to send an endModalSession: message in the event of an exception.

    A loop using these methods is similar to a modal event loop run with runModalForWindow:, except the app can continue processing between method invocations.

    Availability

    Available in OS X v10.0 and later.

  • Runs a given modal session, as defined in a previous invocation of beginModalSessionForWindow:.

    Declaration

    Swift

    func runModalSession(_ session: NSModalSession) -> Int

    Objective-C

    - (NSInteger)runModalSession:(NSModalSession _Nonnull)session

    Parameters

    session

    The modal session structure returned by the beginModalSessionForWindow: method for the window to be displayed.

    Return Value

    An integer indicating the reason that this method returned. See the discussion for a description of possible return values.

    Discussion

    A loop that uses this method is similar in some ways to a modal event loop run with runModalForWindow:, except with this method your code can do some additional work between method invocations. When you invoke this method, events for the NSWindow object of this session are dispatched as normal. This method returns when there are no more events. You must invoke this method frequently enough in your loop that the window remains responsive to events. However, you should not invoke this method in a tight loop because it returns immediately if there are no events, and consequently you could end up polling for events rather than blocking.

    Typically, you use this method in situations where you want to do some additional processing on the current thread while the modal loop runs. For example, while processing a large data set, you might want to use a modal dialog to display progress and give the user a chance to cancel the operation. If you want to display a modal dialog and do not need to do any additional work in parallel, use runModalForWindow: instead. When there are no pending events, that method waits idly instead of consuming CPU time.

    The following code shows a sample loop you can use in your code:

    1. NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
    2. for (;;) {
    3. if ([NSApp runModalSession:session] != NSModalResponseContinue)
    4. break;
    5. [self doSomeWork];
    6. }
    7. [NSApp endModalSession:session];

    If the modal session was not stopped, this method returns NSModalResponseContinue. At this point, your app can do some work before the next invocation of runModalSession: (as indicated in the example’s doSomeWork call). If stopModal was invoked as the result of event processing, runModalSession: returns NSModalResponseStop. If stopModalWithCode: was invoked, this method returns the value passed to stopModalWithCode:. If abortModal was invoked, this method returns NSModalResponseAbort.

    The window is placed on the screen and made key as a result of the runModalSession: message. Do not send a separate makeKeyAndOrderFront: message.

    Availability

    Available in OS X v10.0 and later.

  • The modal window displayed by the app. (read-only)

    Declaration

    Swift

    var modalWindow: NSWindow? { get }

    Objective-C

    @property(readonly, strong, nullable) NSWindow *modalWindow

    Discussion

    This property contains the current standalone modal window or nil if no modal window is being displayed. This property does not contain sheets that are attached to other windows. To retrieve a sheet, use the attachedSheet method of NSWindow.

    Availability

    Available in OS X v10.0 and later.

  • Finishes a modal session.

    Declaration

    Swift

    func endModalSession(_ session: NSModalSession)

    Objective-C

    - (void)endModalSession:(NSModalSession _Nonnull)session

    Parameters

    session

    A modal session structure returned by a previous invocation of beginModalSessionForWindow:.

    Availability

    Available in OS X v10.0 and later.

  • Brings up the color panel, an instance of NSColorPanel.

    Declaration

    Swift

    func orderFrontColorPanel(_ sender: AnyObject?)

    Objective-C

    - (void)orderFrontColorPanel:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    If the NSColorPanel object does not exist yet, this method creates one. This method is typically invoked when the user chooses Colors from a menu.

    Availability

    Available in OS X v10.0 and later.

  • Displays a standard About window.

    Declaration

    Swift

    func orderFrontStandardAboutPanel(_ sender: AnyObject?)

    Objective-C

    - (void)orderFrontStandardAboutPanel:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    This method calls orderFrontStandardAboutPanelWithOptions: with a nil argument. See orderFrontStandardAboutPanelWithOptions: for a description of what’s displayed.

    Availability

    Available in OS X v10.0 and later.

  • Displays a standard About window with information from a given options dictionary.

    Declaration

    Swift

    func orderFrontStandardAboutPanelWithOptions(_ optionsDictionary: [String : AnyObject])

    Objective-C

    - (void)orderFrontStandardAboutPanelWithOptions:(NSDictionary<NSString *,id> * _Nonnull)optionsDictionary

    Parameters

    optionsDictionary

    A dictionary whose keys define the contents of the About window. See the discussion for a description of the available keys.

    Discussion

    The following strings are keys that can occur in optionsDictionary:

    • @"Credits": An NSAttributedString displayed in the info area of the panel. If not specified, this method then looks for a file named “Credits.html”, “Credits.rtf”, and “Credits.rtfd”, in that order, in the bundle returned by the NSBundle class method mainBundle. The first file found is used. If none is found, the info area is left blank.

    • @"ApplicationName": An NSString object displayed as the app’s name. If not specified, this method then uses the value of CFBundleName (localizable). If neither is found, this method uses [[NSProcessInfo processInfo] processName].

    • @"ApplicationIcon": An NSImage object displayed as the app’s icon. If not specified, this method then looks for an image named “NSApplicationIcon”, using [NSImage imageNamed:@"NSApplicationIcon"]. If neither is available, this method uses the generic app icon.

    • @"Version": An NSString object with the build version number of the app (“58.4”), displayed as “(v58.4)”. If not specified, obtain from the CFBundleVersion key in infoDictionary; if not specified, leave blank (the “(v)” is not displayed).

    • @"Copyright": An NSString object with a line of copyright information. If not specified, this method then looks for the value of NSHumanReadableCopyright in the localized version infoDictionary. If neither is available, this method leaves the space blank.

    • @"ApplicationVersion": An NSString object with the app version (“Mac OS X”, “3”, “WebObjects 4.5”, “AppleWorks 6”,...). If not specified, obtain from the CFBundleShortVersionString key in infoDictionary. If neither is available, the build version, if available, is printed alone, as “Version x.x”.

    Availability

    Available in OS X v10.0 and later.

  • Opens the character palette.

    Declaration

    Swift

    func orderFrontCharacterPalette(_ sender: AnyObject?)

    Objective-C

    - (void)orderFrontCharacterPalette:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Availability

    Available in OS X v10.3 and later.

  • Displays the receiver’s page layout panel, an instance of NSPageLayout.

    Declaration

    Swift

    func runPageLayout(_ sender: AnyObject?)

    Objective-C

    - (void)runPageLayout:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    If the NSPageLayout instance does not exist, this method creates one. This method is typically invoked when the user chooses Page Setup from the app’s File menu.

    Availability

    Available in OS X v10.0 and later.

  • Allows an app to extend its state restoration period.

    Declaration

    Swift

    func extendStateRestoration()

    Objective-C

    - (void)extendStateRestoration

    Discussion

    This method allows an app to extend the state restoration period beyond the usual. For example, the app crashes before state restoration is complete, then it may offer to discard restorable state on the next launch.

    If a window has some state that may take a long time to restore, such as a web page, you may use this method and methods to completeStateRestoration to extend the period of this crash protection beyond the default.

    You call extendStateRestoration within your implementation of restoreWindowWithIdentifier:state:completionHandler:. You would then call completeStateRestoration some time after the window is fully restored. If the app crashes in the interim, then it may offer to discard restorable state on the next launch.

    The extendStateRestoration and completeStateRestoration methods act as a counter. Each call to extendStateRestoration increments the counter, and must be matched with a corresponding call to completeStateRestoration which decrements it. When the counter reaches zero, the app is considered to have been fully restored, and any further calls are silently ignored.

    This method is thread safe.

    Availability

    Available in OS X v10.7 and later.

  • Completes the extended state restoration.

    Declaration

    Swift

    func completeStateRestoration()

    Objective-C

    - (void)completeStateRestoration

    Discussion

    This method informs the app that the extended state restoration is completed for the balancing .

    If a window has some state that may take a long time to restore, such as a web page, you may use this method and methods to completeStateRestoration to extend the period of this crash protection beyond the default.

    You call extendStateRestoration within your implementation of restoreWindowWithIdentifier:state:completionHandler:. You would then call completeStateRestoration some time after the window is fully restored. If the app crashes in the interim, then it may offer to discard restorable state on the next launch.

    The extendStateRestoration and completeStateRestoration method act as a counter. Each call to extendStateRestorationincrements the counter, and must be matched with a corresponding call to completeStateRestoration which decrements it. When the counter reaches zero, the app is considered to have been fully restored, and any further calls are silently ignored.

    This method is thread safe.

    Availability

    Available in OS X v10.7 and later.

  • Invoked to request that a window be restored.

    Declaration

    Swift

    func restoreWindowWithIdentifier(_ identifier: String, state state: NSCoder, completionHandler completionHandler: (NSWindow?, NSError?) -> Void) -> Bool

    Objective-C

    - (BOOL)restoreWindowWithIdentifier:(NSString * _Nonnull)identifier state:(NSCoder * _Nonnull)state completionHandler:(void (^ _Nonnull)(NSWindow * _Nullable, NSError * _Nullable))completionHandler

    Parameters

    identifier

    The unique interface item identifier string that was previously associated with the window. Use this string to determine which window to create.

    state

    A coder object containing the window state information. This coder object contains the combined restorable state of the window, which can include the state of the window, its delegate, window controller, and document object. You can use this state to determine which window to create.

    completionHandler

    A Block object to execute with the results of creating the window. You must execute this block at some point but may do so after the method returns if needed. This block takes the following parameters:

    • The window that was created or nil if the window could not be created.

    • An error object if the window was not recognized or could not be created for whatever reason; otherwise, specify nil. In OS X v10.7, the error parameter is ignored.

    Return Value

    YEStrue if the window was restored; otherwise NOfalse.

    Discussion

    If the receiver knows how to restore the identified window, it should invoke the completion handler with the window, possibly creating it. It is acceptable to use a pre-existing window, though you should not pass the same window to more than one completion handler. If the receiver cannot restore the identified window (for example, the window referenced a document that has been deleted), it should invoke the completion handler with a nil window.

    The receiver is app is passed the identifier of the window, which allows it to quickly check for known windows. For example, you might give your preferences window an identifier of "preferences" in the nib, and then check for that identifier in your implementation. The receiver is also passed the NSCoder instance containing the combined restorable state of the window, its delegate, the window controller, and any document. The receiver may decode information previously stored in the coder to determine what window to restore.

    Availability

    Available in OS X v10.7 and later.

  • The window that currently receives keyboard events. (read-only)

    Declaration

    Swift

    unowned(unsafe) var keyWindow: NSWindow? { get }

    Objective-C

    @property(readonly, assign, nullable) NSWindow *keyWindow

    Discussion

    The value of this property is nil when there is no window receiving keyboard events. The property might be nil because the app’s storyboard file has not yet finished loading or when the receiver is not active.

    Availability

    Available in OS X v10.0 and later.

    See Also

    mainWindow
    isKeyWindow (NSWindow)

  • The app’s main window. (read-only)

    Declaration

    Swift

    unowned(unsafe) var mainWindow: NSWindow? { get }

    Objective-C

    @property(readonly, assign, nullable) NSWindow *mainWindow

    Discussion

    The value in this property is nil when the app’s storyboard or nib file has not yet finished loading. It might also be nil when the app is inactive or hidden.

    Availability

    Available in OS X v10.0 and later.

    See Also

    keyWindow
    isMainWindow (NSWindow)

  • Returns the window corresponding to the specified window number.

    Declaration

    Swift

    func windowWithWindowNumber(_ windowNum: Int) -> NSWindow?

    Objective-C

    - (NSWindow * _Nullable)windowWithWindowNumber:(NSInteger)windowNum

    Parameters

    windowNum

    The unique window number associated with the desired NSWindow object.

    Return Value

    The desired window object or nil if the window could not be found.

    Discussion

    windowWithWindowNumber: may return nil for window numbers found using windowNumbersWithOptions: if there is no corresponding window object owned by your app—for example, the menu bar.

    Availability

    Available in OS X v10.0 and later.

  • An array of the app’s window objects. (read-only)

    Declaration

    Swift

    var windows: [NSWindow] { get }

    Objective-C

    @property(readonly, copy, nonnull) NSArray <NSWindow *> *windows

    Discussion

    This property contains an array of NSWindow objects corresponding to all currently existing windows for the app. The array includes all onscreen and offscreen windows, whether or not they are visible on any space. There is no guarantee of the order of the windows in the array.

    Availability

    Available in OS X v10.0 and later.

  • Sends the specified message to each of the app’s window objects until one returns a non-nil value.

    Declaration

    Swift

    func makeWindowsPerform(_ aSelector: Selector, inOrder flag: Bool) -> NSWindow?

    Objective-C

    - (NSWindow * _Nullable)makeWindowsPerform:(SEL _Nonnull)aSelector inOrder:(BOOL)flag

    Parameters

    aSelector

    The selector to perform on each window. This method must not take any arguments and must return a value whose type that can be compared to nil.

    flag

    If YEStrue, the aSelector message is sent to each of the window server’s onscreen windows, going in z-order, until one returns a non-nil value. A minimized window is not considered to be onscreen for this check. If NOfalse, the message is sent to all windows in NSApp’s window list, regardless of whether or not they are onscreen. This order is unspecified.

    Return Value

    The window that returned a non-nil value or nil if all windows returned nil from aSelector.

    Availability

    Available in OS X v10.0 and later.

  • Miniaturizes all the receiver’s windows.

    Declaration

    Swift

    func miniaturizeAll(_ sender: AnyObject?)

    Objective-C

    - (void)miniaturizeAll:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – hide:

  • Sends an update message to each onscreen window.

    Declaration

    Swift

    func updateWindows()

    Objective-C

    - (void)updateWindows

    Discussion

    This method is invoked automatically in the main event loop after each event when running in NSDefaultRunLoopMode or NSModalRunLoopMode. This method is not invoked automatically when running in NSEventTrackingRunLoopMode.

    When this method begins, it posts an NSApplicationWillUpdateNotification to the default notification center. When it successfully completes, it posts an NSApplicationDidUpdateNotification.

    Availability

    Available in OS X v10.0 and later.

    See Also

    update (NSWindow)
    – setWindowsNeedUpdate:
    applicationDidUpdate: (NSApplicationDelegate)
    applicationWillUpdate: (NSApplicationDelegate)

  • Sets whether the receiver’s windows need updating when the receiver has finished processing the current event.

    Declaration

    Swift

    func setWindowsNeedUpdate(_ needUpdate: Bool)

    Objective-C

    - (void)setWindowsNeedUpdate:(BOOL)flag

    Parameters

    flag

    If YEStrue, the receiver’s windows are updated after an event is processed.

    Discussion

    This method is especially useful for making sure menus are updated to reflect changes not initiated by user actions, such as messages received from remote objects.

    Availability

    Available in OS X v10.0 and later.

  • Suppresses the usual window ordering in handling the most recent mouse-down event.

    Declaration

    Swift

    func preventWindowOrdering()

    Objective-C

    - (void)preventWindowOrdering

    Discussion

    This method is only useful for mouse-down events when you want to prevent the window that receives the event from being ordered to the front.

    Availability

    Available in OS X v10.0 and later.

  • Arranges windows listed in the Window menu in front of all other windows.

    Declaration

    Swift

    func arrangeInFront(_ sender: AnyObject?)

    Objective-C

    - (void)arrangeInFront:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    Windows associated with the app but not listed in the Window menu are not ordered to the front.

    Availability

    Available in OS X v10.0 and later.

  • The app’s main menu bar.

    Declaration

    Swift

    var mainMenu: NSMenu?

    Objective-C

    @property(strong, nullable) NSMenu *mainMenu

    Discussion

    Use this property to assign a new menu bar for your app or to access the current menu bar.

    Availability

    Available in OS X v10.0 and later.

  • The Window menu of the app.

    Declaration

    Swift

    var windowsMenu: NSMenu?

    Objective-C

    @property(strong, nullable) NSMenu *windowsMenu

    Return Value

    The window menu or nil if such a menu does not exist or has not yet been created.

    Discussion

    This property contains the app’s Window menu or nil if such a menu does not yet exist or has not yet been created. You can use this property to specify the Window menu for your app.

    Availability

    Available in OS X v10.0 and later.

  • Adds an item to the Window menu for a given window.

    Declaration

    Swift

    func addWindowsItem(_ win: NSWindow, title aString: String, filename isFilename: Bool)

    Objective-C

    - (void)addWindowsItem:(NSWindow * _Nonnull)aWindow title:(NSString * _Nonnull)aString filename:(BOOL)isFilename

    Parameters

    aWindow

    The window being added to the menu. If this window object already exists in the Window menu, this method has no effect.

    aString

    The string to display for the window’s menu item. How the string is interpreted is dependent on the value in the isFilename parameter.

    isFilename

    If NOfalse, aString appears literally in the menu; otherwise, aString is assumed to be a converted pathname with the name of the file preceding the path (the way the NSWindow method setTitleWithRepresentedFilename: shows a title)

    Discussion

    You rarely need to invoke this method directly because Cocoa places an item in the Window menu automatically whenever you set the title of an NSWindow object.

    Availability

    Available in OS X v10.0 and later.

  • Changes the item for a given window in the Window menu to a given string.

    Declaration

    Swift

    func changeWindowsItem(_ win: NSWindow, title aString: String, filename isFilename: Bool)

    Objective-C

    - (void)changeWindowsItem:(NSWindow * _Nonnull)aWindow title:(NSString * _Nonnull)aString filename:(BOOL)isFilename

    Parameters

    aWindow

    The window whose title you want to change in the Window menu. If aWindow is not in the Window menu, this method adds it.

    aString

    The string to display for the window’s menu item. How the string is interpreted is dependent on the value in the isFilename parameter.

    isFilename

    If NOfalse, aString appears literally in the menu; otherwise, aString is assumed to be a converted pathname with the name of the file preceding the path (the way the NSWindow method setTitleWithRepresentedFilename: shows a title)

    Availability

    Available in OS X v10.0 and later.

  • Removes the Window menu item for a given window.

    Declaration

    Swift

    func removeWindowsItem(_ win: NSWindow)

    Objective-C

    - (void)removeWindowsItem:(NSWindow * _Nonnull)aWindow

    Parameters

    aWindow

    The window whose menu item is to be removed.

    Discussion

    This method doesn’t prevent the item from being automatically added again. Use the setExcludedFromWindowsMenu: method of NSWindow if you want the item to remain excluded from the Window menu.

    Availability

    Available in OS X v10.0 and later.

  • Updates the Window menu item for a given window to reflect the edited status of that window.

    Declaration

    Swift

    func updateWindowsItem(_ win: NSWindow)

    Objective-C

    - (void)updateWindowsItem:(NSWindow * _Nonnull)aWindow

    Parameters

    aWindow

    The window whose menu item is to be updated.

    Discussion

    You rarely need to invoke this method because it is invoked automatically when the edit status of an NSWindow object is set.

    Availability

    Available in OS X v10.0 and later.

  • The app’s Dock tile. (read-only)

    Declaration

    Swift

    var dockTile: NSDockTile { get }

    Objective-C

    @property(readonly, strong, nonnull) NSDockTile *dockTile

    Availability

    Available in OS X v10.5 and later.

  • Registers the pasteboard types the receiver can send and receive in response to service requests.

    Declaration

    Swift

    func registerServicesMenuSendTypes(_ sendTypes: [String], returnTypes returnTypes: [String])

    Objective-C

    - (void)registerServicesMenuSendTypes:(NSArray<NSString *> * _Nonnull)sendTypes returnTypes:(NSArray<NSString *> * _Nonnull)returnTypes

    Parameters

    sendTypes

    An array of NSString objects, each of which corresponds to a particular pasteboard type that the app can send.

    returnTypes

    An array of NSString objects, each of which corresponds to a particular pasteboard type that the app can receive.

    Discussion

    If the receiver has a Services menu, a menu item is added for each service provider that can accept one of the specified sendTypes or return one of the specified returnTypes. You should typically invoke this method at app startup time or when an object that can use services is created. You can invoke it more than once—its purpose is to ensure there is a menu item for every service the app can use. The event-handling mechanism will dynamically enable the individual items to indicate which services are currently appropriate. All the NSResponder objects in your app (typically NSView objects) should register every possible type they can send and receive by sending this message to NSApp.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – validRequestorForSendType:returnType:
    readSelectionFromPasteboard: (NSServicesRequests protocol)
    writeSelectionToPasteboard:types: (NSServicesRequests protocol)

  • The app’s Services menu.

    Declaration

    Swift

    var servicesMenu: NSMenu?

    Objective-C

    @property(strong, nullable) NSMenu *servicesMenu

    Discussion

    This property contains the app’s Services menu or nil if that menu has not been created. You can assign a new value to the property to set the Services menu for your app.

    Availability

    Available in OS X v10.0 and later.

  • A Boolean value indicating whether this is the active app. (read-only)

    Declaration

    Swift

    var active: Bool { get }

    Objective-C

    @property(getter=isActive, readonly) BOOL active

    Discussion

    The value of this property is YEStrue if the app is active or NOfalse if it is not.

    Availability

    Available in OS X v10.10 and later.

  • Makes the receiver the active app.

    Declaration

    Swift

    func activateIgnoringOtherApps(_ flag: Bool)

    Objective-C

    - (void)activateIgnoringOtherApps:(BOOL)flag

    Parameters

    flag

    If NOfalse, the app is activated only if no other app is currently active. If YEStrue, the app activates regardless.

    Discussion

    The flag parameter is normally set to NOfalse. When the Finder launches an app, using a value of NOfalse for flag allows the app to become active if the user waits for it to launch, but the app remains unobtrusive if the user activates another app. Regardless of the setting of flag, there may be a time lag before the app activates—you should not assume the app will be active immediately after sending this message.

    You rarely need to invoke this method. Under most circumstances, AppKit takes care of proper activation. However, you might find this method useful if you implement your own methods for inter-app communication.

    You don’t need to send this message to make one of the app’s NSWindows key. When you send a makeKeyWindow message to an NSWindow object, you ensure that it is the key window when the app is active.

    Availability

    Available in OS X v10.0 and later.

  • Deactivates the receiver.

    Declaration

    Swift

    func deactivate()

    Objective-C

    - (void)deactivate

    Discussion

    Normally, you shouldn’t invoke this method—AppKit is responsible for proper deactivation.

    Availability

    Available in OS X v10.0 and later.

  • Hides all apps, except the receiver.

    Declaration

    Swift

    func hideOtherApplications(_ sender: AnyObject?)

    Objective-C

    - (void)hideOtherApplications:(id _Nullable)sender

    Parameters

    sender

    The object that sent this message.

    Availability

    Available in OS X v10.0 and later.

  • Unhides all apps, including the receiver.

    Declaration

    Swift

    func unhideAllApplications(_ sender: AnyObject?)

    Objective-C

    - (void)unhideAllApplications:(id _Nullable)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action causes each app to order its windows to the front, which could obscure the currently active window in the active app.

    Availability

    Available in OS X v10.0 and later.

  • Indicates whether the receiver can send and receive the specified pasteboard types.

    Declaration

    Swift

    func validRequestorForSendType(_ sendType: String, returnType returnType: String) -> AnyObject?

    Objective-C

    - (id _Nullable)validRequestorForSendType:(NSString * _Nonnull)sendType returnType:(NSString * _Nonnull)returnType

    Parameters

    sendType

    The pasteboard type the app needs to send.

    returnType

    The pasteboard type the app needs to receive.

    Return Value

    The object that can send and receive the specified types or nil if the receiver knows of no object that can send and receive data of that type.

    Discussion

    This message is sent to all responders in a responder chain. NSApp is typically the last item in the responder chain, so it usually receives this message only if none of the current responders can send sendType data and accept back returnType data.

    The receiver passes this message on to its delegate if the delegate can respond (and isn’t an NSResponder object with its own next responder). If the delegate cannot respond or returns nil, this method returns nil. If the delegate can find an object that can send sendType data and accept back returnType data, it returns that object.

    Availability

    Available in OS X v10.0 and later.

  • The object that provides the services the current app advertises in the Services menu of other apps.

    Declaration

    Swift

    var servicesProvider: AnyObject?

    Objective-C

    @property(strong, nullable) id servicesProvider

    Return Value

    The app’s service provider object.

    Discussion

    The service provider performs all advertised services for the app. When another app requests a service from the current app, the app object forwards the request to its service provider. Service requests can arrive immediately after the service provider is set, so assign an object to this property only when your app is ready to receive requests.

    Availability

    Available in OS X v10.0 and later.

  • If your project is properly registered, and the necessary keys have been set in the property list, this method launches Help Viewer and displays the first page of your app’s help book.

    Declaration

    Swift

    func showHelp(_ sender: AnyObject?)

    Objective-C

    - (void)showHelp:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    For information on how to set up your project to take advantage of having Help Viewer display your help book, see Specifying the Comprehensive Help File.

    Availability

    Available in OS X v10.0 and later.

  • Places the receiver in context-sensitive help mode.

    Declaration

    Swift

    func activateContextHelpMode(_ sender: AnyObject?)

    Objective-C

    - (void)activateContextHelpMode:(id _Nullable)sender

    Parameters

    sender

    The object that sent the command.

    Discussion

    In this mode, the cursor becomes a question mark, and help appears for any user interface item the user clicks.

    Most apps don’t use this method. Instead, apps enter context-sensitive mode when the user presses the Help key. Apps exit context-sensitive help mode upon the first event after a help window is displayed.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – showHelp:

  • The help menu used by the app.

    Declaration

    Swift

    var helpMenu: NSMenu?

    Objective-C

    @property(strong, nullable) NSMenu *helpMenu

    Discussion

    Use this property to specify your app’s Help menu. When this property contains a valid menu, the system installs its Spotlight-related menu items on that menu. When the value is nil, AppKit installs Spotlight menu items on the menu of its choosing. To suppress Spotlight help items altogether, specify a menu that does not appear on the menu bar.

    Availability

    Available in OS X v10.6 and later.

  • Creates and executes a new thread based on the specified target and selector.

    Declaration

    Swift

    class func detachDrawingThread(_ selector: Selector, toTarget target: AnyObject, withObject argument: AnyObject?)

    Objective-C

    + (void)detachDrawingThread:(SEL _Nonnull)selector toTarget:(id _Nonnull)target withObject:(id _Nullable)argument

    Parameters

    selector

    The selector whose code you want to execute in the new thread.

    target

    The object that defines the specified selector.

    argument

    An optional argument you want to pass to the selector.

    Discussion

    This method is a convenience wrapper for the detachNewThreadSelector:toTarget:withObject: method of NSThread. This method automatically creates an @autoreleasepool block for the new thread before invoking selector.

    Availability

    Available in OS X v10.0 and later.

  • Dispatches an action message to the specified target.

    Declaration

    Swift

    func tryToPerform(_ anAction: Selector, with anObject: AnyObject?) -> Bool

    Objective-C

    - (BOOL)tryToPerform:(SEL _Nonnull)aSelector with:(id _Nullable)anObject

    Parameters

    aSelector

    The action message you want to dispatch.

    anObject

    The target object that defines the specified selector.

    Return Value

    YEStrue if either the receiver or its delegate can accept the specified selector; otherwise, NOfalse. This method also returns NOfalse if aSelector is nil.

    Discussion

    The receiver tries to perform the method aSelector using its inherited tryToPerform:with: method of NSResponder. If the receiver doesn’t perform aSelector, the delegate is given the opportunity to perform it using its inherited performSelector:withObject: method of NSObject.

    Availability

    Available in OS X v10.0 and later.

    See Also

    respondsToSelector: (NSObject protocol)

  • Sends the given action message to the given target.

    Declaration

    Swift

    func sendAction(_ theAction: Selector, to theTarget: AnyObject?, from sender: AnyObject?) -> Bool

    Objective-C

    - (BOOL)sendAction:(SEL _Nonnull)anAction to:(id _Nullable)aTarget from:(id _Nullable)sender

    Parameters

    anAction

    The action message you want to send.

    aTarget

    The target object that defines the specified action message.

    sender

    The object to pass for the action message’s parameter.

    Return Value

    YEStrue if the action was successfully sent; otherwise NOfalse. This method also returns NOfalse if anAction is nil.

    Discussion

    If aTarget is nil, sharedApplication looks for an object that can respond to the message—that is, an object that implements a method matching anAction. It begins with the first responder of the key window. If the first responder can’t respond, it tries the first responder’s next responder and continues following next responder links up the responder chain. If none of the objects in the key window’s responder chain can handle the message, sharedApplication attempts to send the message to the key window’s delegate.

    If the delegate doesn’t respond and the main window is different from the key window, sharedApplication begins again with the first responder in the main window. If objects in the main window can’t respond, sharedApplication attempts to send the message to the main window’s delegate. If still no object has responded, sharedApplication tries to handle the message itself. If sharedApplication can’t respond, it attempts to send the message to its own delegate.

    Availability

    Available in OS X v10.0 and later.

  • Returns the object that receives the action message specified by the given selector

    Declaration

    Swift

    func targetForAction(_ theAction: Selector) -> AnyObject?

    Objective-C

    - (id _Nullable)targetForAction:(SEL _Nonnull)aSelector

    Parameters

    aSelector

    The desired action message.

    Return Value

    The object that would receive the specified action message or nil if no target object would receive the message. This method also returns nil if aSelector is nil.

    Availability

    Available in OS X v10.0 and later.

  • Searches for an object that can receive the message specified by the given selector.

    Declaration

    Swift

    func targetForAction(_ theAction: Selector, to theTarget: AnyObject?, from sender: AnyObject?) -> AnyObject?

    Objective-C

    - (id _Nullable)targetForAction:(SEL _Nonnull)anAction to:(id _Nullable)aTarget from:(id _Nullable)sender

    Parameters

    anAction

    The desired action message. May be nil, in which case this method will return nil.

    aTarget

    The target object to check. Specify nil if you want to search the responder chain starting with the current first responder.

    sender

    The potential sender for the action message.

    Return Value

    The object that can accept the specified action message or nil if no target object can receive the message from the specified sender. Returns nil if anAction is nil.

    Discussion

    The system looks for an object that implements a method matching anAction.

    If aTarget is specified, the system verifies that it is a valid target for the provided action and sender, returning aTarget if valid, nil otherwise.

    If the provided target is nil, the search begins with the first responder of the key window. The system follows the responder chain looking for targets. If no object capable of handling the message is found in the responder chain, returns nil.

    Availability

    Available in OS X v10.0 and later.

  • The graphics context associated with the app. (read-only)

    Declaration

    Swift

    var context: NSGraphicsContext? { get }

    Objective-C

    @property(readonly, strong, nullable) NSGraphicsContext *context

    Discussion

    This property contains the graphics context most recently used by your app.

    Availability

    Available in OS X v10.0 and later.

  • Logs a given exception by calling NSLog().

    Declaration

    Swift

    func reportException(_ theException: NSException)

    Objective-C

    - (void)reportException:(NSException * _Nonnull)anException

    Parameters

    anException

    The exception whose contents you want to write to the log file.

    Discussion

    This method does not raise anException. Use it inside of an exception handler to record that the exception occurred.

    Availability

    Available in OS X v10.0 and later.

    See Also

    NSSetUncaughtExceptionHandler (Foundation Functions)

  • A Boolean value indicating whether Full Keyboard Access is enabled in the Keyboard preference pane. (read-only)

    Declaration

    Swift

    var fullKeyboardAccessEnabled: Bool { get }

    Objective-C

    @property(getter=isFullKeyboardAccessEnabled, readonly) BOOL fullKeyboardAccessEnabled

    Discussion

    The value of this property is YEStrue if Full Keyboard Access is enabled or NOfalse if it is not. You might use this value to implement your own key loop or to implement in-control tabbing behavior similar to NSTableView. Because of the nature of the preference storage, you will not be notified of changes to this property if you attempt to observe it via key-value observing; however, accessing this property is fairly inexpensive, so you can access it directly rather than caching it.

    Availability

    Available in OS X v10.6 and later.

  • Disables relaunching the app on login.

    Declaration

    Swift

    func disableRelaunchOnLogin()

    Objective-C

    - (void)disableRelaunchOnLogin

    Discussion

    Invoking this method will prevent the app from relaunching when the user next logs in to their account.

    If your app should not be relaunched because it launches via some other mechanism (e.g. launchd), then the recommended usage is to call this method once, and never pair it with an enableRelaunchOnLogin method.

    If your app should not be relaunched because it triggers a restart, for example an installer, then the recommended usage is to invoke this method immediately before you attempt to trigger a restart, and enableRelaunchOnLogin immediately after. This is because the user may cancel restarting; if the user later restarts for another reason, then your app should be brought back.

    This methods is thread safe.

    Availability

    Available in OS X v10.7 and later.

  • Enables relaunching the app on login.

    Declaration

    Swift

    func enableRelaunchOnLogin()

    Objective-C

    - (void)enableRelaunchOnLogin

    Discussion

    Invoking this method will cause the app to relaunch when the user next logs in to their account.

    This methods is thread safe.

    Availability

    Available in OS X v10.7 and later.

  • An array of document objects arranged according to the front-to-back ordering of their associated windows. (read-only)

    Declaration

    Swift

    var orderedDocuments: [NSDocument] { get }

    Objective-C

    @property(readonly, copy, nonnull) NSArray <NSDocument *> *orderedDocuments

    Availability

    Available in OS X v10.0 and later.

    See Also

    orderedWindows

  • An array of window objects arranged according to their front-to-back ordering on the screen. (read-only)

    Declaration

    Swift

    var orderedWindows: [NSWindow] { get }

    Objective-C

    @property(readonly, copy, nonnull) NSArray <NSWindow *> *orderedWindows

    Discussion

    Only windows that are typically scriptable are included in the array. For example, panels are not included. This property is accessed during script command evaluation—for example, while finding the window in the script statement close the second window. For information on how your app can return its own array of ordered windows, see application:delegateHandlesKey:.

    Availability

    Available in OS X v10.0 and later.

    See Also

    orderedDocuments

  • Declaration

    Objective-C

    - (NSInteger)runModalForWindow:(NSWindow * _Null_unspecified)theWindow relativeToWindow:(NSWindow * _Null_unspecified)docWindow

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.0.

  • Declaration

    Objective-C

    - (NSModalSession _Nonnull)beginModalSessionForWindow:(NSWindow * _Null_unspecified)theWindow relativeToWindow:(NSWindow * _Null_unspecified)docWindow

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.0.

  • Use the delegate method application:printFiles:withSettings:showPrintPanels: instead.

    Declaration

    Objective-C

    - (void)application:(NSApplication * _Null_unspecified)sender printFiles:(NSArray<NSString *> * _Null_unspecified)filenames

    Parameters

    sender

    Requests application to print file.

    filenames

    The name of the file to print.

    Discussion

    Identical to application:printFile: except that the receiver prints multiple files corresponding to the file names in the filenames array.

    Delegates should invoke the replyToOpenOrPrint: method upon success or failure, or when the user cancels the operation.

    Availability

    Available in OS X v10.3 and later.

    Deprecated in OS X v10.4.

  • Sent by Cocoa’s built-in scripting support during execution of get or set script commands to find out if the delegate can handle operations on the specified key-value key.

    Do not implement this method.

    Declaration

    Swift

    func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool

    Objective-C

    - (BOOL)application:(NSApplication * _Nonnull)sender delegateHandlesKey:(NSString * _Nonnull)key

    Discussion

    The method should return YEStrue if the delegate for the app sender handles the key specified by key, which means it can get or set the scriptable property or element that corresponds to that key. The app implements methods for each of the keys that it handles, where the method name matches the key.

    For example, a scriptable app that doesn’t use Cocoa’s document-based app architecture can implement this method to supply its own document ordering. Such an app might want to do this because the standard app delegate expects to work with a document-based app. The TextEdit app (whose source is distributed with Mac OS X developer tools) provides the following implementation:

    1. return [key isEqualToString:@"orderedDocuments"];

    TextEdit then implements the orderedDocuments method in its controller class to return an ordered list of documents. An app with its own window ordering might add a test for the key orderedWindows so that its delegate can provide its own version of orderedWindows.

    Availability

    Available in OS X v10.0 and later.

    See Also

    orderedDocuments (NSApplication)
    orderedWindows (NSApplication)

  • Starts a document modal session.

    Deprecation Statement

    Use the beginSheet:completionHandler: method of NSWindow instead.

    Declaration

    Swift

    func beginSheet(_ sheet: NSWindow, modalForWindow docWindow: NSWindow, modalDelegate modalDelegate: AnyObject?, didEndSelector didEndSelector: Selector, contextInfo contextInfo: UnsafeMutablePointer<Void>)

    Objective-C

    - (void)beginSheet:(NSWindow * _Nonnull)sheet modalForWindow:(NSWindow * _Nonnull)docWindow modalDelegate:(id _Nullable)modalDelegate didEndSelector:(SEL _Nullable)didEndSelector contextInfo:(void * _Null_unspecified)contextInfo

    Parameters

    sheet

    The window object representing the sheet you want to display.

    docWindow

    The window object to which you want to attach the sheet.

    modalDelegate

    The delegate object that defines your didEndSelector method. If nil, the method in didEndSelector is not called.

    didEndSelector

    An optional method to call when the sheet’s modal session has ended. This method must be defined on the object in the modalDelegate parameter and have the following signature:

    1. - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
    contextInfo

    A pointer to the context info you want passed to the didEndSelector method when the sheet’s modal session ends.

    Discussion

    This method displays the sheet modally on the specified window and returns control to the caller. Most events targeted at docWindow are prohibited while the sheet is displayed but the app’s main run loop runs normally otherwise.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Ends a document modal session by specifying the sheet window.

    Declaration

    Swift

    func endSheet(_ sheet: NSWindow)

    Objective-C

    - (void)endSheet:(NSWindow * _Nonnull)sheet

    Parameters

    sheet

    The sheet whose modal session you want to end.

    Discussion

    This method ends the modal session with the return code NSModalResponseStop.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

  • Ends a document modal session by specifying the sheet window.

    Declaration

    Swift

    func endSheet(_ sheet: NSWindow, returnCode returnCode: Int)

    Objective-C

    - (void)endSheet:(NSWindow * _Nonnull)sheet returnCode:(NSInteger)returnCode

    Parameters

    sheet

    The sheet whose modal session you want to end.

    returnCode

    The return code to send to the delegate. You can use one of the return codes defined in NSModalResponse or a custom value that you define.

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.10.

Data Types

  • Specifies the directional flow of the user interface. These constants are returned by userInterfaceLayoutDirection.

    Declaration

    Swift

    enum NSUserInterfaceLayoutDirection : Int { case LeftToRight case RightToLeft }

    Objective-C

    enum { NSUserInterfaceLayoutDirectionLeftToRight = 0, NSUserInterfaceLayoutDirectionRightToLeft = 1 }; typedef NSInteger NSUserInterfaceLayoutDirection;

    Constants

    • LeftToRight

      NSUserInterfaceLayoutDirectionLeftToRight

      Layout direction is left to right.

      Available in OS X v10.6 and later.

    • RightToLeft

      NSUserInterfaceLayoutDirectionRightToLeft

      Layout direction is right to left. This is appropriate when running with localizations such as Arabic or Hebrew that should have the user interface layout origin on the right edge of the coordinate system.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Return values for -runModalForWindow: and runModalSession:.

    Declaration

    Swift

    typealias NSModalResponse = Int

    Objective-C

    enum { NSModalResponseStop = (-1000), NSModalResponseAbort = (-1001), NSModalResponseContinue = (-1002), }; typedef NSInteger NSModalResponse;

    Constants

    • NSModalResponseStop

      NSModalResponseStop

      Modal session was broken with stopModal.

      This constant is also used as the default response for sheet.

      Available in OS X v10.9 and later.

    • NSModalResponseAbort

      NSModalResponseAbort

      Modal session was broken with abortModal.

      Available in OS X v10.9 and later.

    • NSModalResponseContinue

      NSModalResponseContinue

      Modal session is continuing (returned by runModalSession: only).

      Available in OS X v10.9 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.9 and later.

  • These constants specify the level of severity of a user attention request and are used by cancelUserAttentionRequest: and requestUserAttention:.

    Declaration

    Swift

    enum NSRequestUserAttentionType : UInt { case CriticalRequest case InformationalRequest }

    Objective-C

    enum { NSCriticalRequest = 0, NSInformationalRequest = 10 } typedef NSUInteger NSRequestUserAttentionType;

    Constants

    • CriticalRequest

      NSCriticalRequest

      The user attention request is a critical request.

      The dock icon will bounce until either the app becomes active or the request is canceled.

      Available in OS X v10.1 and later.

    • InformationalRequest

      NSInformationalRequest

      The user attention request is an informational request.

      The dock icon will bounce for one second. The request, though, remains active until either the app becomes active or the request is canceled.

      Available in OS X v10.1 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.1 and later.

  • These constants indicate whether or not a copy or print operation was successful, was cancelled, or failed. These constants are used by the replyToOpenOrPrint: method.

    Declaration

    Swift

    enum NSApplicationDelegateReply : UInt { case Success case Cancel case Failure }

    Objective-C

    enum NSApplicationDelegateReply { NSApplicationDelegateReplySuccess = 0, NSApplicationDelegateReplyCancel = 1, NSApplicationDelegateReplyFailure = 2 } typedef NSUInteger NSApplicationDelegateReply;

    Constants

    • Success

      NSApplicationDelegateReplySuccess

      Indicates the operation succeeded.

      Available in OS X v10.3 and later.

    • Cancel

      NSApplicationDelegateReplyCancel

      Indicates the user cancelled the operation.

      Available in OS X v10.3 and later.

    • Failure

      NSApplicationDelegateReplyFailure

      Indicates an error occurred processing the operation.

      Available in OS X v10.3 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Constants that control the presentation of the app, typically for fullscreen apps such as games or kiosks.

    Declaration

    Swift

    struct NSApplicationPresentationOptions : OptionSetType { init(rawValue rawValue: UInt) static var Default: NSApplicationPresentationOptions { get } static var AutoHideDock: NSApplicationPresentationOptions { get } static var HideDock: NSApplicationPresentationOptions { get } static var AutoHideMenuBar: NSApplicationPresentationOptions { get } static var HideMenuBar: NSApplicationPresentationOptions { get } static var DisableAppleMenu: NSApplicationPresentationOptions { get } static var DisableProcessSwitching: NSApplicationPresentationOptions { get } static var DisableForceQuit: NSApplicationPresentationOptions { get } static var DisableSessionTermination: NSApplicationPresentationOptions { get } static var DisableHideApplication: NSApplicationPresentationOptions { get } static var DisableMenuBarTransparency: NSApplicationPresentationOptions { get } static var FullScreen: NSApplicationPresentationOptions { get } static var AutoHideToolbar: NSApplicationPresentationOptions { get } }

    Objective-C

    enum { NSApplicationPresentationDefault = 0, NSApplicationPresentationAutoHideDock = (1 << 0), NSApplicationPresentationHideDock = (1 << 1), NSApplicationPresentationAutoHideMenuBar = (1 << 2), NSApplicationPresentationHideMenuBar = (1 << 3), NSApplicationPresentationDisableAppleMenu = (1 << 4), NSApplicationPresentationDisableProcessSwitching = (1 << 5), NSApplicationPresentationDisableForceQuit = (1 << 6), NSApplicationPresentationDisableSessionTermination = (1 << 7), NSApplicationPresentationDisableHideApplication = (1 << 8), NSApplicationPresentationDisableMenuBarTransparency = (1 << 9) NSApplicationPresentationFullScreen = (1 << 10), NSApplicationPresentationAutoHideToolbar = (1 << 11) }; typedef NSUInteger NSApplicationPresentationOptions;

    Constants

    • Default

      NSApplicationPresentationDefault

      This is the default presentation mode. The dock and menu bar are displayed, process switching is enabled, force quit is enabled, session termination is enabled, the hide menu is enabled, and the menu bar transparency is normal.

      Available in OS X v10.6 and later.

    • AutoHideDock

      NSApplicationPresentationAutoHideDock

      The dock is normally hidden, but automatically appears when moused near.

      Available in OS X v10.6 and later.

    • HideDock

      NSApplicationPresentationHideDock

      The dock is entirely hidden and disabled.

      Available in OS X v10.6 and later.

    • AutoHideMenuBar

      NSApplicationPresentationAutoHideMenuBar

      The menu bar is normally hidden, but automatically appears when moused near.

      Available in OS X v10.6 and later.

    • HideMenuBar

      NSApplicationPresentationHideMenuBar

      The menu bar is entirely hidden and disabled.

      Available in OS X v10.6 and later.

    • DisableAppleMenu

      NSApplicationPresentationDisableAppleMenu

      All Apple Menu items are disabled.

      Available in OS X v10.6 and later.

    • DisableProcessSwitching

      NSApplicationPresentationDisableProcessSwitching

      The process switching user interface (Command + Tab to cycle through apps) is disabled.

      Available in OS X v10.6 and later.

    • DisableForceQuit

      NSApplicationPresentationDisableForceQuit

      The force quit panel (displayed by pressing Command + Option + Esc) is disabled

      Available in OS X v10.6 and later.

    • DisableSessionTermination

      NSApplicationPresentationDisableSessionTermination

      The panel that shows the Restart, Shut Down, and Log Out options that are displayed as a result of pushing the power key is disabled.

      Available in OS X v10.6 and later.

    • DisableHideApplication

      NSApplicationPresentationDisableHideApplication

      The app’s “Hide” menu item is disabled.

      Available in OS X v10.6 and later.

    • DisableMenuBarTransparency

      NSApplicationPresentationDisableMenuBarTransparency

      The menu bar transparency appearance is disabled.

      Available in OS X v10.6 and later.

    • FullScreen

      NSApplicationPresentationFullScreen

      The app is in fullscreen mode.

      Available in OS X v10.7 and later.

    • AutoHideToolbar

      NSApplicationPresentationAutoHideToolbar

      When in fullscreen mode the window toolbar is detached from window and hides and shows with autoHidden menuBar.

      Available in OS X v10.7 and later.

    Discussion

    There are restrictions on the combination of presentation options that can be set simultaneously:

    When setPresentationOptions: receives a parameter value that does not conform to these requirements, it raises an NSInvalidArgumentException.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • These constants define whether an app should terminate and are used by the delegate method applicationShouldTerminate:.

    Declaration

    Swift

    enum NSApplicationTerminateReply : UInt { case TerminateCancel case TerminateNow case TerminateLater }

    Objective-C

    enum { NSTerminateCancel = 0, NSTerminateNow = 1, NSTerminateLater = 2 } typedef NSUInteger NSApplicationTerminateReply;

    Constants

    • TerminateNow

      NSTerminateNow

      It is OK to proceed with termination.

      Available in OS X v10.0 and later.

    • TerminateCancel

      NSTerminateCancel

      The app should not be terminated.

      Available in OS X v10.0 and later.

    • TerminateLater

      NSTerminateLater

      It may be OK to proceed with termination later. Returning this value causes Cocoa to run the run loop in the NSModalPanelRunLoopMode until your app subsequently calls replyToApplicationShouldTerminate: with the value YEStrue or NOfalse. This return value is for delegates that need to provide document modal alerts (sheets) in order to decide whether to quit.

      Available in OS X v10.0 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • These constants are returned by the delegate method application:printFiles:withSettings:showPrintPanels:.

    Declaration

    Swift

    enum NSApplicationPrintReply : UInt { case PrintingCancelled case PrintingSuccess case PrintingFailure case PrintingReplyLater }

    Objective-C

    enum { NSPrintingCancelled = 0, NSPrintingSuccess = 1, NSPrintingFailure = 3, NSPrintingReplyLater = 2 } typedef NSUInteger NSApplicationPrintReply;

    Constants

    • PrintingCancelled

      NSPrintingCancelled

      Printing was cancelled.

      Available in OS X v10.4 and later.

    • PrintingSuccess

      NSPrintingSuccess

      Printing was successful.

      Available in OS X v10.4 and later.

    • PrintingFailure

      NSPrintingFailure

      Printing failed.

      Available in OS X v10.4 and later.

    • PrintingReplyLater

      NSPrintingReplyLater

      The result of printing cannot be returned immediately, for example, if printing will cause the presentation of a sheet. If your method returns NSPrintingReplyLater it must always invoke replyToOpenOrPrint: when the entire print operation has been completed, successfully or not.

      Available in OS X v10.4 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • This constants indicates whether at least part of any window owned by this app is visible.

    Declaration

    Swift

    struct NSApplicationOcclusionState : OptionSetType { init(rawValue rawValue: UInt) static var Visible: NSApplicationOcclusionState { get } }

    Objective-C

    typedef NS_OPTIONS(NSUInteger, NSApplicationOcclusionState) { NSApplicationOcclusionStateVisible = 1UL << 1, }

    Constants

    • Visible

      NSApplicationOcclusionStateVisible

      If set, at least part of any window owned by this app is visible.

      If not set, all parts of all windows owned by this app are completely occluded. The menu bar does not count as a window owned by this app, so if only the menu bar is showing then the app is considered not visible. Status items, however, have windows owned by your app. If the status item is present in the menu bar, your app will be considered visible as long as the menu bar is visible.

      Available in OS X v10.9 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.9 and later.

  • A global constant for the shared app instance.

    Declaration

    Swift

    var NSApp: NSApplication!

    Objective-C

    id NSApp

    Constants

    • NSApp

      NSApp

      Global constant for the shared app instance. This is the same as sending the NSApplication class the method sharedApplication message.

      Available in OS X v10.0 and later.

    Discussion

    This variable designates the shared app object, created by the sharedApplication method.

  • Historical return values for runModalForWindow: and runModalSession:.

    Declaration

    Swift

    var NSRunStoppedResponse: Int { get } var NSRunAbortedResponse: Int { get } var NSRunContinuesResponse: Int { get }

    Objective-C

    enum { NSRunStoppedResponse = (-1000), NSRunAbortedResponse = (-1001), NSRunContinuesResponse = (-1002) };

    Constants

    • NSRunStoppedResponse

      NSRunStoppedResponse

      Modal session was broken with stopModal.

      Use NSModalResponseStop instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.10.

    • NSRunAbortedResponse

      NSRunAbortedResponse

      Modal session was broken with abortModal.

      Use NSModalResponseAbort instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.10.

    • NSRunContinuesResponse

      NSRunContinuesResponse

      Modal session is continuing (returned by runModalSession: only).

      Use NSModalResponseContinue instead.

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.10.

    Discussion

    The system also reserves all values below these.

  • This constant is used by the NSRunLoop method performSelector:target:argument:order:modes:.

    Declaration

    Swift

    var NSUpdateWindowsRunLoopOrdering: Int { get }

    Objective-C

    enum { NSUpdateWindowsRunLoopOrdering = 500000 };

    Constants

    • NSUpdateWindowsRunLoopOrdering

      NSUpdateWindowsRunLoopOrdering

      Run-loop message priority for handling window updates.

      Available in OS X v10.0 and later.

  • These loop mode constants are defined by NSApplication.

    Declaration

    Swift

    let NSEventTrackingRunLoopMode: String let NSModalPanelRunLoopMode: String

    Objective-C

    NSString *NSModalPanelRunLoopMode; NSString *NSEventTrackingRunLoopMode;

    Constants

    • NSEventTrackingRunLoopMode

      NSEventTrackingRunLoopMode

      A run loop should be set to this mode when tracking events modally, such as a mouse-dragging loop.

      Available in OS X v10.0 and later.

    • NSModalPanelRunLoopMode

      NSModalPanelRunLoopMode

      A run loop should be set to this mode when waiting for input from a modal panel, such as NSSavePanel or NSOpenPanel.

      Available in OS X v10.0 and later.

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

    Declaration

    Swift

    let NSApplicationLaunchIsDefaultLaunchKey: String let NSApplicationLaunchUserNotificationKey: String

    Objective-C

    NSString * const NSApplicationLaunchRemoteNotificationKey; NSString * const NSApplicationLaunchIsDefaultLaunchKey; NSString * const NSApplicationLaunchUserNotificationKey;

    Constants

    • NSApplicationLaunchRemoteNotificationKey

      Use this key to access the JSON push-notification payload from the userInfo dictionary of the NSApplicationDidFinishLaunchingNotification notification. This notification is passed into the delegate method application:didFinishLaunching: declared by the NSApplicationDelegate Protocol protocol to handle this notification. For information about the payload dictionary, see Local and Remote Notification Programming Guide.

      Available in OS X v10.7 and later.

      Deprecated in OS X v10.8.

    • NSApplicationLaunchIsDefaultLaunchKey

      NSApplicationLaunchIsDefaultLaunchKey

      The value for this key is an NSNumber containing a Boolean value. The value is NOfalse if the app was launched to open or print a file, to perform a Service action, if the app had saved state that will be restored, or if the app launch was in some other sense not a default launch. Otherwise its value will be YEStrue.

      Available in OS X v10.7 and later.

    • NSApplicationLaunchUserNotificationKey

      NSApplicationLaunchUserNotificationKey

      The following key is an NSUserNotification object that will be present in the notification userInfo dictionary of the NSApplicationDidFinishLaunchingNotification notification if your app was launched because a user activated a notification in the Notification Center.

      Available in OS X v10.8 and later.

  • These constants determine whether apps launched by remote notifications display a badge.

    Declaration

    Swift

    struct NSRemoteNotificationType : OptionSetType { init(rawValue rawValue: UInt) static var None: NSRemoteNotificationType { get } static var Badge: NSRemoteNotificationType { get } static var Sound: NSRemoteNotificationType { get } static var Alert: NSRemoteNotificationType { get } }

    Objective-C

    enum { NSRemoteNotificationTypeNone = 0, NSRemoteNotificationTypeBadge = 1 << 0 NSRemoteNotificationTypeSound = 1 << 1, NSRemoteNotificationTypeAlert = 1 << 2, }; typedef NSUInteger NSRemoteNotificationType;

    Constants

    • None

      NSRemoteNotificationTypeNone

      The app should not display a badge.

      Available in OS X v10.7 and later.

    • Badge

      NSRemoteNotificationTypeBadge

      The app should display a badge.

      Available in OS X v10.7 and later.

    • Sound

      NSRemoteNotificationTypeSound

      The app should play a sound.

      Available in OS X v10.8 and later.

    • Alert

      NSRemoteNotificationTypeAlert

      The app should display an alert.

      Available in OS X v10.8 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • This constant identifies the installed version of the AppKit framework.

    Declaration

    Swift

    let NSAppKitVersionNumber: Double

    Objective-C

    const double NSAppKitVersionNumber;

    Constants

    • NSAppKitVersionNumber

      NSAppKitVersionNumber

      This value corresponds to one of the constants defined in AppKit framework version numbers.

      Available in OS X v10.1 and later.

  • You can use the following constants to determine if you are using a version of the AppKit framework newer than the version delivered in Mac OS X v10.0.

    Declaration

    Swift

    var NSAppKitVersionNumber10_0: Int32 { get } var NSAppKitVersionNumber10_1: Int32 { get } var NSAppKitVersionNumber10_2: Int32 { get } var NSAppKitVersionNumber10_2_3: Double { get } var NSAppKitVersionNumber10_3: Int32 { get } var NSAppKitVersionNumber10_3_2: Double { get } var NSAppKitVersionNumber10_3_3: Double { get } var NSAppKitVersionNumber10_3_5: Double { get } var NSAppKitVersionNumber10_3_7: Double { get } var NSAppKitVersionNumber10_3_9: Double { get } var NSAppKitVersionNumber10_4: Int32 { get } var NSAppKitVersionNumber10_4_1: Double { get } var NSAppKitVersionNumber10_4_3: Double { get } var NSAppKitVersionNumber10_4_4: Double { get } var NSAppKitVersionNumber10_4_7: Double { get } var NSAppKitVersionNumber10_5: Int32 { get } var NSAppKitVersionNumber10_5_2: Double { get } var NSAppKitVersionNumber10_5_3: Double { get } var NSAppKitVersionNumber10_6: Int32 { get } var NSAppKitVersionNumber10_7: Int32 { get } var NSAppKitVersionNumber10_7_2: Double { get } var NSAppKitVersionNumber10_7_3: Double { get } var NSAppKitVersionNumber10_7_4: Double { get } var NSAppKitVersionNumber10_8: Int32 { get }

    Objective-C

    #define NSAppKitVersionNumber10_0 577 #define NSAppKitVersionNumber10_1 620 #define NSAppKitVersionNumber10_2 663 #define NSAppKitVersionNumber10_2_3 663.6 #define NSAppKitVersionNumber10_3 743 #define NSAppKitVersionNumber10_3_2 743.14 #define NSAppKitVersionNumber10_3_3 743.2 #define NSAppKitVersionNumber10_3_5 743.24 #define NSAppKitVersionNumber10_3_7 743.33 #define NSAppKitVersionNumber10_3_9 743.36 #define NSAppKitVersionNumber10_4 824 #define NSAppKitVersionNumber10_4_1 824.1 #define NSAppKitVersionNumber10_4_3 824.23 #define NSAppKitVersionNumber10_4_4 824.33 #define NSAppKitVersionNumber10_4_7 824.41 #define NSAppKitVersionNumber10_5 949 #define NSAppKitVersionNumber10_5_2 949.27 #define NSAppKitVersionNumber10_5_3 949.33 #define NSAppKitVersionNumber10_6 1038 #define NSAppKitVersionNumber10_7 1138 #define NSAppKitVersionNumber10_7_2 1138.23

    Constants

    • NSAppKitVersionNumber10_0

      NSAppKitVersionNumber10_0

      The AppKit framework included in OS X v10.0.

      Available in OS X v10.1 and later.

    • NSAppKitVersionNumber10_1

      NSAppKitVersionNumber10_1

      The AppKit framework included in OS X v10.1.

      Available in OS X v10.2 and later.

    • NSAppKitVersionNumber10_2

      NSAppKitVersionNumber10_2

      The AppKit framework included in OS X v10.2.

      Available in OS X v10.3 and later.

    • NSAppKitVersionNumber10_2_3

      NSAppKitVersionNumber10_2_3

      The AppKit framework included in OS X v10.2.3.

      Available in OS X v10.3 and later.

    • NSAppKitVersionNumber10_3

      NSAppKitVersionNumber10_3

      The AppKit framework included in OS X v10.3.

      Available in OS X v10.4 and later.

    • NSAppKitVersionNumber10_3_2

      NSAppKitVersionNumber10_3_2

      The AppKit framework included in OS X v10.3.2.

      Available in OS X v10.4 and later.

    • NSAppKitVersionNumber10_3_3

      NSAppKitVersionNumber10_3_3

      The AppKit framework included in OS X v10.3.3.

      Available in OS X v10.4 and later.

    • NSAppKitVersionNumber10_3_5

      NSAppKitVersionNumber10_3_5

      The AppKit framework included in OS X v10.3.5.

      Available in OS X v10.4 and later.

    • NSAppKitVersionNumber10_3_7

      NSAppKitVersionNumber10_3_7

      The AppKit framework included in OS X v10.3.7.

      Available in OS X v10.5 and later.

    • NSAppKitVersionNumber10_3_9

      NSAppKitVersionNumber10_3_9

      The AppKit framework included in OS X v10.3.9.

      Available in OS X v10.5 and later.

    • NSAppKitVersionNumber10_4

      NSAppKitVersionNumber10_4

      The AppKit framework included in OS X v10.4.

      Available in OS X v10.5 and later.

    • NSAppKitVersionNumber10_4_1

      NSAppKitVersionNumber10_4_1

      The AppKit framework included in OS X v10.4.1.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_4_3

      NSAppKitVersionNumber10_4_3

      The AppKit framework included in OS X v10.4.3.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_4_4

      NSAppKitVersionNumber10_4_4

      The AppKit framework included in OS X v10.4.4.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_4_7

      NSAppKitVersionNumber10_4_7

      The AppKit framework included in OS X v10.4.7.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_5

      NSAppKitVersionNumber10_5

      The AppKit framework included in OS X v10.5.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_5_2

      NSAppKitVersionNumber10_5_2

      The AppKit framework included in OS X v10.5.2.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_5_3

      NSAppKitVersionNumber10_5_3

      The AppKit framework included in OS X v10.5.3.

      Available in OS X v10.6 and later.

    • NSAppKitVersionNumber10_6

      NSAppKitVersionNumber10_6

      The AppKit framework included in OS X v10.6.

      Available in OS X v10.7 and later.

    • NSAppKitVersionNumber10_7

      NSAppKitVersionNumber10_7

      The AppKit framework included in OS X v10.7.

      Available in OS X v10.7 and later.

    • NSAppKitVersionNumber10_7_2

      NSAppKitVersionNumber10_7_2

      The AppKit framework included in OS X v10.7.2.

      Available in OS X v10.7 and later.

    • NSAppKitVersionNumber10_7_3

      NSAppKitVersionNumber10_7_3

      The AppKit framework included in OS X v10.7.3.

      Available in OS X v10.9 and later.

    • NSAppKitVersionNumber10_7_4

      NSAppKitVersionNumber10_7_4

      The AppKit framework included in OS X v10.7.4.

      Available in OS X v10.9 and later.

    • NSAppKitVersionNumber10_8

      NSAppKitVersionNumber10_8

      The AppKit framework included in OS X v10.8.

      Available in OS X v10.9 and later.