O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How the NSUndoManager Works

Suppose that the user opens a new RaiseMan document and makes three edits:

  1. Inserts a new record

  2. Changes the name from New Employee to John Locke

  3. Changes the raise from 5 to 20

To support undo, as each edit is performed your controller will add an invocation that would undo that edit to the undo stack. For the sake of simplifying the prose, let’s say, “The inverse of the edit gets added to the undo stack.”

Figure 11.1 shows what the undo stack would look like after these three edits.

Figure 11.1  The undo stack

The undo stack

If the user now chooses the Undo menu item, the first invocation is taken ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required