Suppose you have a set of actions to be performed and you want o undo the changes, you can use NSUndoManager.
NSUndoManager piles all the actions on to a stack so that you when you want to undo them, the action that is last added to the stack is popped out and you get the previous action.
It keeps Undo as well as the Redo stack.
Code below allocs the NSUndoManager object.
NSUndoManager *undoManager = [[NSUndoManager alloc] init];
First you need to register the object that you want to Undo with the NSUndoManager object.
[[undoManager prepareWithInvocationTarget:self] user_method:object];
where user_method: is the action that is recorded by the undoManager object which it uses to undo and redo the action.
NSUndoManager takes care of all the changes by adding these actions to its undo and redo stack.
To undo an action, simply call “undo” on the NSUndoManager object.
To redo an action, you call “redo” on NSUndoManager object.
To check if you can undo an action, you can use canUndo on NSUndoManager object.
to check if you can redo an action, you can use canRedo on NSUndoManager object.
To set number of levels of undo, use setLevelsOfUndo