<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSResponder",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSResponder"
  },
  "title" : "NSResponder"
}
-->

# NSResponder

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

```
@MainActor class NSResponder
```

## Overview

The core classes—[`NSApplication`](/documentation/AppKit/NSApplication), [`NSWindow`](/documentation/AppKit/NSWindow), and [`NSView`](/documentation/AppKit/NSView)—inherit from [`NSResponder`](/documentation/AppKit/NSResponder), as must any class that handles events. The responder model uses three components: event messages, action messages, and the responder chain.

[`NSResponder`](/documentation/AppKit/NSResponder) also plays an important role in the presentation of error information. The default implementations of the [`presentError(_:)`](/documentation/AppKit/NSResponder/presentError(_:)) and [`presentError(_:modalFor:delegate:didPresent:contextInfo:)`](/documentation/AppKit/NSResponder/presentError(_:modalFor:delegate:didPresent:contextInfo:)) methods send [`willPresentError(_:)`](/documentation/AppKit/NSResponder/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 <doc://com.apple.documentation/documentation/Foundation/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`](/documentation/AppKit/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 <doc://com.apple.documentation/documentation/Foundation/nserrorrecoveryattempting> informal protocol.

> Note:
> In macOS 10.15 and later, ``doc://com.apple.appkit/documentation/AppKit/NSResponder`` and its descendants call the <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/dealloc> method on the main thread. This method helps to avoid situations where an asynchronous block unexpectedly deallocates an object on a background queue.

## Topics

### Changing the First Responder

[`var acceptsFirstResponder: Bool`](/documentation/AppKit/NSResponder/acceptsFirstResponder)

A Boolean value that indicates whether the responder accepts first responder status.

[`func becomeFirstResponder() -> Bool`](/documentation/AppKit/NSResponder/becomeFirstResponder())

Notifies the receiver that it’s about to become first responder in its [`NSWindow`](/documentation/AppKit/NSWindow).

[`func resignFirstResponder() -> Bool`](/documentation/AppKit/NSResponder/resignFirstResponder())

Notifies the receiver that it’s been asked to relinquish its status as first responder in its window.

[`func validateProposedFirstResponder(NSResponder, for: NSEvent?) -> Bool`](/documentation/AppKit/NSResponder/validateProposedFirstResponder(_:for:))

Allows controls to determine when they should become first responder.

### Managing the Next Responder

[`var nextResponder: NSResponder?`](/documentation/AppKit/NSResponder/nextResponder)

The next responder after this one, or `nil` if it has none.

### Responding to Mouse Events

[`func mouseDown(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseDown(with:))

Informs the receiver that the user has pressed the left mouse button.

[`func mouseDragged(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseDragged(with:))

Informs the receiver that the user has moved the mouse with the left button pressed.

[`func mouseUp(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseUp(with:))

Informs the receiver that the user has released the left mouse button.

[`func mouseMoved(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseMoved(with:))

Informs the receiver that the mouse has moved.

[`func mouseEntered(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseEntered(with:))

Informs the receiver that the cursor has entered a tracking rectangle.

[`func mouseExited(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseExited(with:))

Informs the receiver that the cursor has exited a tracking rectangle.

[`func rightMouseDown(with: NSEvent)`](/documentation/AppKit/NSResponder/rightMouseDown(with:))

Informs the receiver that the user has pressed the right mouse button.

[`func rightMouseDragged(with: NSEvent)`](/documentation/AppKit/NSResponder/rightMouseDragged(with:))

Informs the receiver that the user has moved the mouse with the right button pressed.

[`func rightMouseUp(with: NSEvent)`](/documentation/AppKit/NSResponder/rightMouseUp(with:))

Informs the receiver that the user has released the right mouse button.

[`func otherMouseDown(with: NSEvent)`](/documentation/AppKit/NSResponder/otherMouseDown(with:))

Informs the receiver that the user has pressed a mouse button other than the left or right one.

[`func otherMouseDragged(with: NSEvent)`](/documentation/AppKit/NSResponder/otherMouseDragged(with:))

Informs the receiver that the user has moved the mouse with a button other than the left or right button pressed.

[`func otherMouseUp(with: NSEvent)`](/documentation/AppKit/NSResponder/otherMouseUp(with:))

Informs the receiver that the user has released a mouse button other than the left or right button.

### Responding to Key Events

[`func keyDown(with: NSEvent)`](/documentation/AppKit/NSResponder/keyDown(with:))

Informs the receiver that the user has pressed a key.

[`func keyUp(with: NSEvent)`](/documentation/AppKit/NSResponder/keyUp(with:))

Informs the receiver that the user has released a key.

[`func interpretKeyEvents([NSEvent])`](/documentation/AppKit/NSResponder/interpretKeyEvents(_:))

Handles a series of key events.

[`func performKeyEquivalent(with: NSEvent) -> Bool`](/documentation/AppKit/NSResponder/performKeyEquivalent(with:))

Handle a key equivalent.

[`func flushBufferedKeyEvents()`](/documentation/AppKit/NSResponder/flushBufferedKeyEvents())

Clears any unprocessed key events when overridden by subclasses.

### Responding to Pressure Changes

[`func pressureChange(with: NSEvent)`](/documentation/AppKit/NSResponder/pressureChange(with:))

Indicates a pressure change as the result of a user input event on a system that supports pressure sensitivity.

### Responding to Other Kinds of Events

[`func cursorUpdate(with: NSEvent)`](/documentation/AppKit/NSResponder/cursorUpdate(with:))

Informs the receiver that the mouse cursor has moved into a cursor rectangle.

[`func flagsChanged(with: NSEvent)`](/documentation/AppKit/NSResponder/flagsChanged(with:))

Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

[`func tabletPoint(with: NSEvent)`](/documentation/AppKit/NSResponder/tabletPoint(with:))

Informs the receiver that a tablet-point event has occurred.

[`func tabletProximity(with: NSEvent)`](/documentation/AppKit/NSResponder/tabletProximity(with:))

Informs the receiver that a tablet-proximity event has occurred.

[`func helpRequested(NSEvent)`](/documentation/AppKit/NSResponder/helpRequested(_:))

Displays context-sensitive help for the receiver if help has been registered.

[`func scrollWheel(with: NSEvent)`](/documentation/AppKit/NSResponder/scrollWheel(with:))

Informs the receiver that the mouse’s scroll wheel has moved.

[`func quickLook(with: NSEvent)`](/documentation/AppKit/NSResponder/quickLook(with:))

Performs a Quick Look on the content at the location specified by the supplied event.

[`func changeMode(with: NSEvent)`](/documentation/AppKit/NSResponder/changeMode(with:))

Informs the responder that performed a double-tap on the side of an Apple Pencil.

### Responding to Action Messages

[`func supplementalTarget(forAction: Selector, sender: Any?) -> Any?`](/documentation/AppKit/NSResponder/supplementalTarget(forAction:sender:))

Finds a target for an action method.

[`protocol NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

Methods that responder subclasses implement to support key binding commands, such as inserting tabs and newlines, or moving the insertion point.

[Action Messages](/documentation/AppKit/action-messages)

Implement action messages in your first responders to handle common tasks.

### Handling Window Restoration

[`class func allowedClasses(forRestorableStateKeyPath: String) -> [AnyClass]`](/documentation/AppKit/NSResponder/allowedClasses(forRestorableStateKeyPath:))

Returns the classes that support secure coding.

[`func encodeRestorableState(with: NSCoder)`](/documentation/AppKit/NSResponder/encodeRestorableState(with:))

Saves the interface-related state of the responder.

[`func encodeRestorableState(with: NSCoder, backgroundQueue: OperationQueue)`](/documentation/AppKit/NSResponder/encodeRestorableState(with:backgroundQueue:))

Saves the interface-related state of the responder to a keyed archiver either synchronously or asynchronously on the given operation queue.

[`func restoreState(with: NSCoder)`](/documentation/AppKit/NSResponder/restoreState(with:))

Restores the interface-related state of the responder.

[`class var restorableStateKeyPaths: [String]`](/documentation/AppKit/NSResponder/restorableStateKeyPaths)

Returns an array of key paths representing the restorable attributes of the responder.

[`func invalidateRestorableState()`](/documentation/AppKit/NSResponder/invalidateRestorableState())

Marks the responder’s interface-related state as dirty.

### Supporting User Activities

[`var userActivity: NSUserActivity?`](/documentation/AppKit/NSResponder/userActivity)

An object encapsulating a user activity supported by this responder.

[`func updateUserActivityState(NSUserActivity)`](/documentation/AppKit/NSResponder/updateUserActivityState(_:))

Updates the state of the given user activity.

### Presenting and Customizing Error Information

[`func presentError(any Error) -> Bool`](/documentation/AppKit/NSResponder/presentError(_:))

Presents an error alert to the user as an application-modal dialog.

[`func presentError(any Error, modalFor: NSWindow, delegate: Any?, didPresent: Selector?, contextInfo: UnsafeMutableRawPointer?)`](/documentation/AppKit/NSResponder/presentError(_:modalFor:delegate:didPresent:contextInfo:))

Presents an error alert to the user as a document-modal sheet attached to document window.

[`func willPresentError(any Error) -> any Error`](/documentation/AppKit/NSResponder/willPresentError(_:))

Returns a custom version of the supplied error object that’s more suitable for presentation in alert sheets and dialogs.

### Dispatching Messages

[`func tryToPerform(Selector, with: Any?) -> Bool`](/documentation/AppKit/NSResponder/tryToPerform(_:with:))

Attempts to perform the method indicated by an action with a specified argument.

### Managing a Responder’s Menu

[`var menu: NSMenu?`](/documentation/AppKit/NSResponder/menu)

Returns the responder’s menu.

### Updating the Services Menu

[`func validRequestor(forSendType: NSPasteboard.PasteboardType?, returnType: NSPasteboard.PasteboardType?) -> Any?`](/documentation/AppKit/NSResponder/validRequestor(forSendType:returnType:))

Overridden by subclasses to determine what services are available.

### Getting the Undo Manager

[`var undoManager: UndoManager?`](/documentation/AppKit/NSResponder/undoManager)

The undo manager for this responder.

### Testing Events

[`func shouldBeTreatedAsInkEvent(NSEvent) -> Bool`](/documentation/AppKit/NSResponder/shouldBeTreatedAsInkEvent(_:))

Indicates whether a pen-down event should be treated as an ink event.

### Terminating the Responder Chain

[`func noResponder(for: Selector)`](/documentation/AppKit/NSResponder/noResponder(for:))

Handles the case where an event or action message falls off the end of the responder chain.

### Touch and Gesture Events

[`func magnify(with: NSEvent)`](/documentation/AppKit/NSResponder/magnify(with:))

Informs the receiver that the user has begun a pinch gesture.

[`func rotate(with: NSEvent)`](/documentation/AppKit/NSResponder/rotate(with:))

Informs the receiver that the user has begun a rotation gesture.

[`func swipe(with: NSEvent)`](/documentation/AppKit/NSResponder/swipe(with:))

Informs the receiver that the user has begun a swipe gesture.

[`func touchesBegan(with: NSEvent)`](/documentation/AppKit/NSResponder/touchesBegan(with:))

Informs the receiver that new set of touches has been recognized.

[`func touchesMoved(with: NSEvent)`](/documentation/AppKit/NSResponder/touchesMoved(with:))

Informs the receiver that one or more touches has moved.

[`func touchesCancelled(with: NSEvent)`](/documentation/AppKit/NSResponder/touchesCancelled(with:))

Informs the receiver that tracking of touches has been cancelled for any reason.

[`func touchesEnded(with: NSEvent)`](/documentation/AppKit/NSResponder/touchesEnded(with:))

Returns that a set of touches have been removed.

[`func wantsForwardedScrollEvents(for: NSEvent.GestureAxis) -> Bool`](/documentation/AppKit/NSResponder/wantsForwardedScrollEvents(for:))

Returns whether to forward elastic scrolling gesture events up the responder.

[`func smartMagnify(with: NSEvent)`](/documentation/AppKit/NSResponder/smartMagnify(with:))

Informs the receiver that the user performed a smart zoom gesture.

[`func wantsScrollEventsForSwipeTracking(on: NSEvent.GestureAxis) -> Bool`](/documentation/AppKit/NSResponder/wantsScrollEventsForSwipeTracking(on:))

Implement this method to track gesture scroll events such as a swipe.

[`enum GestureAxis`](/documentation/AppKit/NSEvent/GestureAxis)

Constants that specify the direction of travel for a gesture.

### Supporting the Touch Bar

[`var touchBar: NSTouchBar?`](/documentation/AppKit/NSResponder/touchBar)

The [`NSTouchBar`](/documentation/AppKit/NSTouchBar) object associated with the responder.

[`func makeTouchBar() -> NSTouchBar?`](/documentation/AppKit/NSResponder/makeTouchBar())

Your custom subclass of the `NSResponder` class should override this method to create and configure your subclass’s default [`NSTouchBar`](/documentation/AppKit/NSTouchBar) object.

### Performing Text Find Actions

[`func performTextFinderAction(Any?)`](/documentation/AppKit/NSResponder/performTextFinderAction(_:))

Performs all find oriented actions.

### Supporting Tabbed Windows

[`func newWindowForTab(Any?)`](/documentation/AppKit/NSResponder/newWindowForTab(_:))

Creates a new window to show as a tab in a tabbed window.

### Creating Responders

[`init()`](/documentation/AppKit/NSResponder/init())

Creates a new responder object.

[`init?(coder: NSCoder)`](/documentation/AppKit/NSResponder/init(coder:))

Creates a new responder object with data in an unarchiver.

### Deprecated

[Deprecated symbols](/documentation/AppKit/nsresponder-deprecated-symbols)

Review symbols that are no longer in active development, and their recommended replacements.

### Instance Methods

[`func contextMenuKeyDown(NSEvent)`](/documentation/AppKit/NSResponder/contextMenuKeyDown(_:))

[`func mouseCancelled(with: NSEvent)`](/documentation/AppKit/NSResponder/mouseCancelled(with:))

[`func showWritingTools(Any?)`](/documentation/AppKit/NSResponder/showWritingTools(_:))

## Relationships

### Inherited By

[`NSView`](/documentation/AppKit/NSView)

[`NSDrawer`](/documentation/AppKit/NSDrawer)

[`NSWindow`](/documentation/AppKit/NSWindow)

[`NSViewController`](/documentation/AppKit/NSViewController)

[`NSApplication`](/documentation/AppKit/NSApplication)

[`NSPopover`](/documentation/AppKit/NSPopover)

[`NSWindowController`](/documentation/AppKit/NSWindowController)

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`Sendable`](/documentation/Swift/Sendable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Copyable`](/documentation/Swift/Copyable)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`Escapable`](/documentation/Swift/Escapable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)