<!--
{
  "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

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

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

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

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

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

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

[`validateProposedFirstResponder(_:for:)`](/documentation/AppKit/NSResponder/validateProposedFirstResponder(_:for:))

Allows controls to determine when they should become first responder.

### Managing the Next Responder

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

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

### Responding to Mouse Events

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

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

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

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

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

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

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

Informs the receiver that the mouse has moved.

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

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

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

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

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

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

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

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

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

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

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

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

[`otherMouseDragged(with:)`](/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.

[`otherMouseUp(with:)`](/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

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

Informs the receiver that the user has pressed a key.

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

Informs the receiver that the user has released a key.

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

Handles a series of key events.

[`performKeyEquivalent(with:)`](/documentation/AppKit/NSResponder/performKeyEquivalent(with:))

Handle a key equivalent.

[`performMnemonic:`](/documentation/AppKit/NSResponder/performMnemonic:)

Handle a mnemonic.

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

Clears any unprocessed key events when overridden by subclasses.

### Responding to Pressure Changes

[`pressureChange(with:)`](/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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### Responding to Action Messages

[`supplementalTarget(forAction:sender:)`](/documentation/AppKit/NSResponder/supplementalTarget(forAction:sender:))

Finds a target for an action method.

[`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

[`allowedClasses(forRestorableStateKeyPath:)`](/documentation/AppKit/NSResponder/allowedClasses(forRestorableStateKeyPath:))

Returns the classes that support secure coding.

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

Saves the interface-related state of the responder.

[`encodeRestorableState(with:backgroundQueue:)`](/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.

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

Restores the interface-related state of the responder.

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

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

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

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

### Supporting User Activities

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

An object encapsulating a user activity supported by this responder.

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

Updates the state of the given user activity.

### Presenting and Customizing Error Information

[`presentError(_:)`](/documentation/AppKit/NSResponder/presentError(_:))

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

[`presentError(_:modalFor:delegate:didPresent:contextInfo:)`](/documentation/AppKit/NSResponder/presentError(_:modalFor:delegate:didPresent:contextInfo:))

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

[`willPresentError(_:)`](/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

[`tryToPerform(_:with:)`](/documentation/AppKit/NSResponder/tryToPerform(_:with:))

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

### Managing a Responder’s Menu

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

Returns the responder’s menu.

### Updating the Services Menu

[`validRequestor(forSendType:returnType:)`](/documentation/AppKit/NSResponder/validRequestor(forSendType:returnType:))

Overridden by subclasses to determine what services are available.

### Getting the Undo Manager

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

The undo manager for this responder.

### Testing Events

[`shouldBeTreatedAsInkEvent(_:)`](/documentation/AppKit/NSResponder/shouldBeTreatedAsInkEvent(_:))

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

### Terminating the Responder Chain

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

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

### Setting the Interface Style

[`setInterfaceStyle:`](/documentation/AppKit/NSResponder/setInterfaceStyle:)

Sets the receiver’s style to the style specified by `interfaceStyle`, such as `NSMacintoshInterfaceStyle` or `NSWindows95InterfaceStyle`.

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

Returns the receiver’s interface style.

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

For more information, see the function [`NSInterfaceStyleForKey`](/documentation/AppKit/NSInterfaceStyleForKey).

### Touch and Gesture Events

[`beginGesture(with:)`](/documentation/AppKit/NSResponder/beginGesture(with:))

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

[`endGesture(with:)`](/documentation/AppKit/NSResponder/endGesture(with:))

Informs the receiver that the user has ended a touch gesture.

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

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

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

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

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

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

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

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

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

Informs the receiver that one or more touches has moved.

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

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

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

Returns that a set of touches have been removed.

[`wantsForwardedScrollEvents(for:)`](/documentation/AppKit/NSResponder/wantsForwardedScrollEvents(for:))

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

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

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

[`wantsScrollEventsForSwipeTracking(on:)`](/documentation/AppKit/NSResponder/wantsScrollEventsForSwipeTracking(on:))

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

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

Constants that specify the direction of travel for a gesture.

### Supporting the Touch Bar

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

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

[`makeTouchBar()`](/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

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

Performs all find oriented actions.

### Supporting Tabbed Windows

[`newWindowForTab(_:)`](/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:)`](/documentation/AppKit/NSResponder/init(coder:))

Creates a new responder object with data in an unarchiver.



---

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)