<!--
{
  "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/levelsOfUndo",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUndoManager(py)levelsOfUndo"
  },
  "title" : "levelsOfUndo"
}
-->

# levelsOfUndo

The maximum number of top-level undo groups the undo manager holds.

```
var levelsOfUndo: Int { get set }
```

## Discussion

An integer specifying the number of undo groups. A limit of `0` indicates no limit, so the manager never drops old undo groups.

When ending an undo group results in the number of groups exceeding this limit, the manager drops the oldest groups from the stack. The default is `0`.

If you change the limit to a level below the prior limit, the manager immediately drops old undo groups.

## See Also

[`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)