---
title: UndoManager
framework: foundation
role: symbol
role_heading: Class
path: foundation/undomanager
---

# UndoManager

A general-purpose recorder of operations that enables undo and redo.

## Declaration

```swift
@MainActor class UndoManager
```

## Overview

Overview You register an undo operation by calling one of the methods described in Registering undo operations. You specify the name of the object that’s changing (or the owner of that object) and provide a closure, method, or invocation to revert its state. After you register an undo operation, you can call undo() on the undo manager to revert to the state of the last undo operation. When undoing an action, UndoManager saves the operations you revert to so that you can call redo() automatically. Typically, apps with UI interactions work with UndoManager. For example, UIKit implements undo and redo in its text view object, making it easy for you to undo and redo actions in objects along the responder chain. UndoManager also serves as a general-purpose state manager, which you can use to undo and redo many kinds of actions. For example, an interactive command-line utility can use this class to undo the last command run, or a networking library can undo a request by sending another request that invalidates the previous one. important: UndoManager is MainActor-isolated in Swift, making it safe to use in UI frameworks like AppKit and UIKit that expect to execute code on the main thread, queue, or actor. When registering an undoable action with registerUndo(withTarget:handler:), the handler closure is also MainActor-isolated to ensure safety and simplify ergonomics.

## Topics

### Registering undo operations

- [registerUndo(withTarget:handler:)](foundation/undomanager/registerundo(withtarget:handler:).md)
- [registerUndo(withTarget:selector:object:)](foundation/undomanager/registerundo(withtarget:selector:object:).md)
- [prepare(withInvocationTarget:)](foundation/undomanager/prepare(withinvocationtarget:).md)

### Checking undo ability

- [canUndo](foundation/undomanager/canundo.md)
- [canRedo](foundation/undomanager/canredo.md)

### Performing undo and redo

- [undo()](foundation/undomanager/undo().md)
- [undoNestedGroup()](foundation/undomanager/undonestedgroup().md)
- [redo()](foundation/undomanager/redo().md)

### Managing undo and redo stack depth

- [levelsOfUndo](foundation/undomanager/levelsofundo.md)
- [undoCount](foundation/undomanager/undocount.md)
- [redoCount](foundation/undomanager/redocount.md)

### Creating undo groups

- [beginUndoGrouping()](foundation/undomanager/beginundogrouping().md)
- [endUndoGrouping()](foundation/undomanager/endundogrouping().md)
- [groupsByEvent](foundation/undomanager/groupsbyevent.md)
- [groupingLevel](foundation/undomanager/groupinglevel.md)

### Enabling and disabling undo

- [disableUndoRegistration()](foundation/undomanager/disableundoregistration().md)
- [enableUndoRegistration()](foundation/undomanager/enableundoregistration().md)
- [isUndoRegistrationEnabled](foundation/undomanager/isundoregistrationenabled.md)

### Checking whether undo or redo is in process

- [isUndoing](foundation/undomanager/isundoing.md)
- [isRedoing](foundation/undomanager/isredoing.md)

### Clearing undo operations

- [removeAllActions()](foundation/undomanager/removeallactions().md)
- [removeAllActions(withTarget:)](foundation/undomanager/removeallactions(withtarget:).md)

### Managing the action name

- [undoActionName](foundation/undomanager/undoactionname.md)
- [redoActionName](foundation/undomanager/redoactionname.md)
- [setActionName(_:)](foundation/undomanager/setactionname(_:)-cci9.md)
- [setActionName(_:)](foundation/undomanager/setactionname(_:)-8lzip.md)

### Getting and localizing the menu item title

- [undoMenuItemTitle](foundation/undomanager/undomenuitemtitle.md)
- [redoMenuItemTitle](foundation/undomanager/redomenuitemtitle.md)
- [undoMenuTitle(forUndoActionName:)](foundation/undomanager/undomenutitle(forundoactionname:).md)
- [redoMenuTitle(forUndoActionName:)](foundation/undomanager/redomenutitle(forundoactionname:).md)

### Working with user info

- [setActionUserInfoValue(_:forKey:)](foundation/undomanager/setactionuserinfovalue(_:forkey:).md)
- [undoActionUserInfoValue(forKey:)](foundation/undomanager/undoactionuserinfovalue(forkey:).md)
- [redoActionUserInfoValue(forKey:)](foundation/undomanager/redoactionuserinfovalue(forkey:).md)
- [UndoManager.UserInfoKey](foundation/undomanager/userinfokey.md)

### Working with run loops

- [runLoopModes](foundation/undomanager/runloopmodes.md)
- [NSUndoCloseGroupingRunLoopOrdering](foundation/nsundoclosegroupingrunloopordering.md)

### Using discardable undo and redo actions

- [setActionIsDiscardable(_:)](foundation/undomanager/setactionisdiscardable(_:).md)
- [undoActionIsDiscardable](foundation/undomanager/undoactionisdiscardable.md)
- [redoActionIsDiscardable](foundation/undomanager/redoactionisdiscardable.md)

### Working with notifications

- [NSUndoManagerWillUndoChange](foundation/nsnotification/name-swift.struct/nsundomanagerwillundochange.md)
- [NSUndoManagerDidUndoChange](foundation/nsnotification/name-swift.struct/nsundomanagerdidundochange.md)
- [NSUndoManagerWillRedoChange](foundation/nsnotification/name-swift.struct/nsundomanagerwillredochange.md)
- [NSUndoManagerDidRedoChange](foundation/nsnotification/name-swift.struct/nsundomanagerdidredochange.md)
- [NSUndoManagerCheckpoint](foundation/nsnotification/name-swift.struct/nsundomanagercheckpoint.md)
- [NSUndoManagerDidOpenUndoGroup](foundation/nsnotification/name-swift.struct/nsundomanagerdidopenundogroup.md)
- [NSUndoManagerWillCloseUndoGroup](foundation/nsnotification/name-swift.struct/nsundomanagerwillcloseundogroup.md)
- [NSUndoManagerDidCloseUndoGroup](foundation/nsnotification/name-swift.struct/nsundomanagerdidcloseundogroup.md)
- [NSUndoManagerGroupIsDiscardableKey](foundation/nsundomanagergroupisdiscardablekey.md)

### Working with notification messages

- [UndoManager.WillUndoChangeMessage](foundation/undomanager/willundochangemessage.md)
- [UndoManager.DidUndoChangeMessage](foundation/undomanager/didundochangemessage.md)
- [UndoManager.WillRedoChangeMessage](foundation/undomanager/willredochangemessage.md)
- [UndoManager.DidRedoChangeMessage](foundation/undomanager/didredochangemessage.md)
- [UndoManager.CheckpointMessage](foundation/undomanager/checkpointmessage.md)
- [UndoManager.DidOpenUndoGroupMessage](foundation/undomanager/didopenundogroupmessage.md)
- [UndoManager.WillCloseUndoGroupMessage](foundation/undomanager/willcloseundogroupmessage.md)
- [UndoManager.DidCloseUndoGroupMessage](foundation/undomanager/didcloseundogroupmessage.md)

## Relationships

### Inherits From

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

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
