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

# undoManager

The object that the document uses to support undo/redo operations.

```
var undoManager: UndoManager? { get set }
```

## Discussion

When the [`hasUndoManager`](/documentation/AppKit/NSDocument/hasUndoManager) property is <doc://com.apple.documentation/documentation/Swift/true>, accessing this property creates an <doc://com.apple.documentation/documentation/Foundation/UndoManager> before returning it. If the [`hasUndoManager`](/documentation/AppKit/NSDocument/hasUndoManager) property is <doc://com.apple.documentation/documentation/Swift/false>, the value of this property is `nil` by default. Assigning an undo manager to this property stores a reference to the object and automatically changes the [`hasUndoManager`](/documentation/AppKit/NSDocument/hasUndoManager) property to <doc://com.apple.documentation/documentation/Swift/true>.

Whether you assign an undo manager or let the document create one, the document registers itself as an observer of various  <doc://com.apple.documentation/documentation/Foundation/UndoManager> notifications so that appropriate document actions are stored on the undo stack.

---

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)