NSResponder
An abstract class that forms the basis of event and command processing in AppKit.
Declaration
@MainActor class NSResponderOverview
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
acceptsFirstResponderbecomeFirstResponder()resignFirstResponder()validateProposedFirstResponder(_:for:)
Managing the Next Responder
Responding to Mouse Events
mouseDown(with:)mouseDragged(with:)mouseUp(with:)mouseMoved(with:)mouseEntered(with:)mouseExited(with:)rightMouseDown(with:)rightMouseDragged(with:)rightMouseUp(with:)otherMouseDown(with:)otherMouseDragged(with:)otherMouseUp(with:)
Responding to Key Events
Responding to Pressure Changes
Responding to Other Kinds of Events
cursorUpdate(with:)flagsChanged(with:)tabletPoint(with:)tabletProximity(with:)helpRequested(_:)scrollWheel(with:)quickLook(with:)changeMode(with:)
Responding to Action Messages
Handling Window Restoration
allowedClasses(forRestorableStateKeyPath:)encodeRestorableState(with:)encodeRestorableState(with:backgroundQueue:)restoreState(with:)restorableStateKeyPathsinvalidateRestorableState()
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
beginGesture(with:)endGesture(with:)magnify(with:)rotate(with:)swipe(with:)touchesBegan(with:)touchesMoved(with:)touchesCancelled(with:)touchesEnded(with:)wantsForwardedScrollEvents(for:)smartMagnify(with:)wantsScrollEventsForSwipeTracking(on:)NSEvent.GestureAxis