Contents

NSResponder

An abstract class that forms the basis of event and command processing in AppKit.

Declaration

@MainActor class NSResponder

Overview

The core classes—NSApplication, NSWindow, and NSView—inherit from NSResponder, as must any class that handles events. The responder model uses three components: event messages, action messages, and the responder chain.

NSResponder also plays an important role in the presentation of error information. The default implementations of the presentError(_:) and presentError(_:modalFor:delegate:didPresent:contextInfo:) methods send willPresentError(_:) to self, thereby giving subclasses the opportunity to customize the localized information presented in error alerts. NSResponder then forwards the message to the next responder, passing it the customized NSError object. The exact path up the modified responder chain depends on the type of application window:

  • Window that the document owns: view > superviews > window > window controller > document object > document controller > the application object

  • Window with window controller but no documents: view > superviews > window > window controller > the application object

  • Window with no window controllers: view > superviews > window > the application object

NSApplication displays a document-modal error alert and, if the error object has a recovery attempter, gives it a chance to recover from the error. A recovery attempter is an object that conforms to the NSErrorRecoveryAttempting informal protocol.

Topics

Changing the First Responder

Managing the Next Responder

Responding to Mouse Events

Responding to Key Events

Responding to Pressure Changes

Responding to Other Kinds of Events

Responding to Action Messages

Handling Window Restoration

Supporting User Activities

Presenting and Customizing Error Information

Dispatching Messages

Managing a Responder’s Menu

Updating the Services Menu

Getting the Undo Manager

Testing Events

Terminating the Responder Chain

Touch and Gesture Events

Supporting the Touch Bar

Performing Text Find Actions

Supporting Tabbed Windows

Creating Responders

Instance Methods