Registers the specified closure to implement a single undo operation that the target receives.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 7.0+
The target of the undo operation.
The undo manager maintains an unowned reference to the
targetto prevent retain cycles.
A closure to be executed when an operation is undone.
The closure takes a single argument, the target of the undo operation.
register to register a closure as an undo operation on the undo stack. The registered closure is then executed when
undo is called and the undo operation occurs. The target needs to be a reference type so that its state can be undone or redone by the undo manager.
The following example demonstrates how you can use this method to register an undo operation that adds an element back into a mutable array.
To avoid retain cycles with the target, operate on the closure parameter rather than on variables in an outer scope that reference the same target. For example, in the code listing above, the closure operates on the
$0 parameter rather than directly on