You’re previewing Ry’s Cocoa Tutorial

Undo/Redo

Undo/redo functionality is a fundamental part of an OS X application. It frees the user from the fear of permanently damaging their data. If they accidentally change something they didn’t mean to, they can simply hit Edit > Undo (or the Command+Z shortcut), and they’re back to safety. This is an incredible feature of digital documents when compared to their physical counterparts, and it’s worth taking advantage of in your own applications.

Cocoa provides comprehensive undo/redo support via its NSUndoManager class. It’s designed to be highly reusable, so you can leverage it regardless of whether your app deals with text documents, image data, or custom file formats.

Integrating an undo manager into the MVC pattern

The general idea is to record all of the changes to a model object using NSUndoManager. These changes can then be re-applied to the model object to restore its previous state. In this chapter, we’ll explore the conceptual details behind this functionality, then we’ll walk through a simple example project that demonstrates how NSUndoManager is typically integrated into a Mac App.

Sorry, this is the end of the preview. To read the rest of this chapter, you’ll need to purchase Ry’s Cocoa Tutorial.

Mailing List

Sign up for my low-volume mailing list to find out when new content is released. Next up is a comprehensive Swift tutorial planned for late January.

You’ll only receive emails when new tutorials are released, and your contact information will never be shared with third parties. Click here to unsubscribe.