---
title: undo()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/undomanager/undo()
---

# undo()

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

## Declaration

```swift
func undo()
```

## Discussion

Discussion After closing the top-level undo group, this method invokes undoNestedGroup(). This method also invokes 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.

## See Also

### Related Documentation

- [groupingLevel](foundation/undomanager/groupinglevel.md)
- [enableUndoRegistration()](foundation/undomanager/enableundoregistration().md)

### Performing undo and redo

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