<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/UndoManager/undo()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUndoManager(im)undo"
  },
  "title" : "undo()"
}
-->

# undo()

Closes the top-level undo group if necessary, and then performs undo operations on the group.

```
func undo()
```

## Discussion

After closing the top-level undo group, this method invokes [`undoNestedGroup()`](/documentation/Foundation/UndoManager/undoNestedGroup()).

This method also invokes [`endUndoGrouping()`](/documentation/Foundation/UndoManager/endUndoGrouping()) if the nesting level is 1. Raises an `NSInternalInconsistencyException` if more than one undo group is open (that is, if the last group isn’t at the top level).

This method posts an [`NSUndoManagerCheckpoint`](/documentation/Foundation/NSNotification/Name-swift.struct/NSUndoManagerCheckpoint).

## See Also

[`groupingLevel`](/documentation/Foundation/UndoManager/groupingLevel)

The number of nested undo groups (or redo groups, if redo is the most recent operation) in the current event loop.

[`enableUndoRegistration()`](/documentation/Foundation/UndoManager/enableUndoRegistration())

Enables the recording of undo operations.



---

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)