Registers the selector of the specified target to implement a single undo operation that the target receives.
- iOS 3.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
The target of the undo operation.
The undo manager maintains an unowned reference to
targetto prevent retain cycles.
The selector for the undo operation.
The argument sent with the selector.
The undo manager maintains a strong reference to
register to register a selector for an undo operation. To register a selector on the undo stack, you also need to make the method available to the Objective-C runtime by applying the @
objc attribute to the method. For more on how to create a selector, see Selectors.
Calling this method also clears the redo stack.
The following example demonstrates how to register and use a selector on the undo stack by modeling a
Garden class with two methods:
plant(flower:) method removes a flower from the garden while
pluck(flower:) adds a flower such that effectively, the two methods are inverse operations of each other. This inverse quality makes it ideal to register
pluck(flower:) to be each other's undo operation.