Use the NSUndoManager. However, if you are painting lines on the canvas, you will also need to keep their representation around as well (so you can pop them off).
So, whether you collect them as a UIBezierPath, or use shape layers, or your own "array of points" you undo in the same manner.
So, while drawing the line, keep a record of the points you used in your drawing. When the drawing is done (e.g., touchesEnded), you want to "push" your drawing, and tell the undo manager how to undo it. Simply, it would be something like this almost-code...
- (void)pushDrawing:(Drawing*)drawing
{
[self.stack push:drawing];
[self.undoManager registerUndoWithTarget: self
selector: @selector(popDrawing)
object: nil];
}
- (void)popDrawing:(Drawing*)drawing
{
Drawing *drawing = [self.stack pop];
[self.undoManager registerUndoWithTarget: self
selector: @selector(pushDrawing:)
object: drawing];
}
If you are using one canvas, you may have to redraw the entire thing, especially when popping a drawing off. If you are using views or layers, you may not...
Look at the docs for NSUndoManager... it's available on iOS, and has good examples. It "remembers" if you you undo-ing or redo-ing, and will do the right thing, so the above could be implemented as one function (but it's easier to understand at first with one function going each direction).