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

For the More Curious: Windows and the Undo Manager

A view can add inverse actions for its edits to the undo manager. NSTextView, for example, can put the undo action for each edit that the user makes to the text onto the undo manager. How does the text view know which undo manager to use? First, it asks its delegate. NSTextView delegates can implement this method:

o​p​t​i​o​n​a​l​ ​f​u​n​c​ ​u​n​d​o​M​a​n​a​g​e​r​F​o​r​T​e​x​t​V​i​e​w​(​v​i​e​w​:​ ​N​S​T​e​x​t​V​i​e​w​!​)​ ​-​>​ ​N​S​U​n​d​o​M​a​n​a​g​e​r​?​

Next, it asks its window. NSWindow inherits a property for this purpose from NSResponder:

v​a​r​ ​u​n​d​o​M​a​n​a​g​e​r​:​ ​N​S​U​n​d​o​M​a​n​a​g​e​r​?​ ​{​ ​g​e​t​ ​}​

The window’s delegate can supply an undo manager for the ...

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