---
title: NSResponder
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsresponder
---

# NSResponder

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

## Declaration

```swift
@MainActor class NSResponder
```

## Overview

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. note: In macOS 10.15 and later, NSResponder and its descendants call the 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](appkit/nsresponder/acceptsfirstresponder.md)
- [becomeFirstResponder()](appkit/nsresponder/becomefirstresponder().md)
- [resignFirstResponder()](appkit/nsresponder/resignfirstresponder().md)
- [validateProposedFirstResponder(_:for:)](appkit/nsresponder/validateproposedfirstresponder(_:for:).md)

### Managing the Next Responder

- [nextResponder](appkit/nsresponder/nextresponder.md)

### Responding to Mouse Events

- [mouseDown(with:)](appkit/nsresponder/mousedown(with:).md)
- [mouseDragged(with:)](appkit/nsresponder/mousedragged(with:).md)
- [mouseUp(with:)](appkit/nsresponder/mouseup(with:).md)
- [mouseMoved(with:)](appkit/nsresponder/mousemoved(with:).md)
- [mouseEntered(with:)](appkit/nsresponder/mouseentered(with:).md)
- [mouseExited(with:)](appkit/nsresponder/mouseexited(with:).md)
- [rightMouseDown(with:)](appkit/nsresponder/rightmousedown(with:).md)
- [rightMouseDragged(with:)](appkit/nsresponder/rightmousedragged(with:).md)
- [rightMouseUp(with:)](appkit/nsresponder/rightmouseup(with:).md)
- [otherMouseDown(with:)](appkit/nsresponder/othermousedown(with:).md)
- [otherMouseDragged(with:)](appkit/nsresponder/othermousedragged(with:).md)
- [otherMouseUp(with:)](appkit/nsresponder/othermouseup(with:).md)

### Responding to Key Events

- [keyDown(with:)](appkit/nsresponder/keydown(with:).md)
- [keyUp(with:)](appkit/nsresponder/keyup(with:).md)
- [interpretKeyEvents(_:)](appkit/nsresponder/interpretkeyevents(_:).md)
- [performKeyEquivalent(with:)](appkit/nsresponder/performkeyequivalent(with:).md)
- [flushBufferedKeyEvents()](appkit/nsresponder/flushbufferedkeyevents().md)

### Responding to Pressure Changes

- [pressureChange(with:)](appkit/nsresponder/pressurechange(with:).md)

### Responding to Other Kinds of Events

- [cursorUpdate(with:)](appkit/nsresponder/cursorupdate(with:).md)
- [flagsChanged(with:)](appkit/nsresponder/flagschanged(with:).md)
- [tabletPoint(with:)](appkit/nsresponder/tabletpoint(with:).md)
- [tabletProximity(with:)](appkit/nsresponder/tabletproximity(with:).md)
- [helpRequested(_:)](appkit/nsresponder/helprequested(_:).md)
- [scrollWheel(with:)](appkit/nsresponder/scrollwheel(with:).md)
- [quickLook(with:)](appkit/nsresponder/quicklook(with:).md)
- [changeMode(with:)](appkit/nsresponder/changemode(with:).md)

### Responding to Action Messages

- [supplementalTarget(forAction:sender:)](appkit/nsresponder/supplementaltarget(foraction:sender:).md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [Action Messages](appkit/action-messages.md)

### Handling Window Restoration

- [allowedClasses(forRestorableStateKeyPath:)](appkit/nsresponder/allowedclasses(forrestorablestatekeypath:).md)
- [encodeRestorableState(with:)](appkit/nsresponder/encoderestorablestate(with:).md)
- [encodeRestorableState(with:backgroundQueue:)](appkit/nsresponder/encoderestorablestate(with:backgroundqueue:).md)
- [restoreState(with:)](appkit/nsresponder/restorestate(with:).md)
- [restorableStateKeyPaths](appkit/nsresponder/restorablestatekeypaths.md)
- [invalidateRestorableState()](appkit/nsresponder/invalidaterestorablestate().md)

### Supporting User Activities

- [userActivity](appkit/nsresponder/useractivity.md)
- [updateUserActivityState(_:)](appkit/nsresponder/updateuseractivitystate(_:).md)

### Presenting and Customizing Error Information

- [presentError(_:)](appkit/nsresponder/presenterror(_:).md)
- [presentError(_:modalFor:delegate:didPresent:contextInfo:)](appkit/nsresponder/presenterror(_:modalfor:delegate:didpresent:contextinfo:).md)
- [willPresentError(_:)](appkit/nsresponder/willpresenterror(_:).md)

### Dispatching Messages

- [tryToPerform(_:with:)](appkit/nsresponder/trytoperform(_:with:).md)

### Managing a Responder’s Menu

- [menu](appkit/nsresponder/menu.md)

### Updating the Services Menu

- [validRequestor(forSendType:returnType:)](appkit/nsresponder/validrequestor(forsendtype:returntype:).md)

### Getting the Undo Manager

- [undoManager](appkit/nsresponder/undomanager.md)

### Testing Events

- [shouldBeTreatedAsInkEvent(_:)](appkit/nsresponder/shouldbetreatedasinkevent(_:).md)

### Terminating the Responder Chain

- [noResponder(for:)](appkit/nsresponder/noresponder(for:).md)

### Touch and Gesture Events

- [beginGesture(with:)](appkit/nsresponder/begingesture(with:).md)
- [endGesture(with:)](appkit/nsresponder/endgesture(with:).md)
- [magnify(with:)](appkit/nsresponder/magnify(with:).md)
- [rotate(with:)](appkit/nsresponder/rotate(with:).md)
- [swipe(with:)](appkit/nsresponder/swipe(with:).md)
- [touchesBegan(with:)](appkit/nsresponder/touchesbegan(with:).md)
- [touchesMoved(with:)](appkit/nsresponder/touchesmoved(with:).md)
- [touchesCancelled(with:)](appkit/nsresponder/touchescancelled(with:).md)
- [touchesEnded(with:)](appkit/nsresponder/touchesended(with:).md)
- [wantsForwardedScrollEvents(for:)](appkit/nsresponder/wantsforwardedscrollevents(for:).md)
- [smartMagnify(with:)](appkit/nsresponder/smartmagnify(with:).md)
- [wantsScrollEventsForSwipeTracking(on:)](appkit/nsresponder/wantsscrolleventsforswipetracking(on:).md)
- [NSEvent.GestureAxis](appkit/nsevent/gestureaxis.md)

### Supporting the Touch Bar

- [touchBar](appkit/nsresponder/touchbar.md)
- [makeTouchBar()](appkit/nsresponder/maketouchbar().md)

### Performing Text Find Actions

- [performTextFinderAction(_:)](appkit/nsresponder/performtextfinderaction(_:).md)

### Supporting Tabbed Windows

- [newWindowForTab(_:)](appkit/nsresponder/newwindowfortab(_:).md)

### Creating Responders

- [init()](appkit/nsresponder/init().md)
- [init(coder:)](appkit/nsresponder/init(coder:).md)

### Instance Methods

- [contextMenuKeyDown(_:)](appkit/nsresponder/contextmenukeydown(_:).md)
- [mouseCancelled(with:)](appkit/nsresponder/mousecancelled(with:).md)
- [showWritingTools(_:)](appkit/nsresponder/showwritingtools(_:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSApplication](appkit/nsapplication.md)
- [NSDrawer](appkit/nsdrawer.md)
- [NSPopover](appkit/nspopover.md)
- [NSView](appkit/nsview.md)
- [NSViewController](appkit/nsviewcontroller.md)
- [NSWindow](appkit/nswindow.md)
- [NSWindowController](appkit/nswindowcontroller.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [Sendable](swift/sendable.md)
