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

Undo for Edits

It is time now for you to add undo support for editing of employees’s fields to RaiseMan. The first step is to register Document to observe changes to the Employee objects in its employees array. Add the following private variable near the top of Document.swift:

i​m​p​o​r​t​ ​C​o​c​o​a​

p​r​i​v​a​t​e​ ​v​a​r​ ​K​V​O​C​o​n​t​e​x​t​:​ ​I​n​t​ ​=​ ​0​

c​l​a​s​s​ ​D​o​c​u​m​e​n​t​:​ ​N​S​D​o​c​u​m​e​n​t​ ​{​

You will use the KVOContext variable to get a unique value to use as the KVO context pointer.

Next, add this section inside the Document implementation:

 ​ ​ ​ ​/​/​ ​M​A​R​K​:​ ​-​ ​K​e​y​ ​V​a​l​u​e​ ​O​b​s​e​r​v​i​n​g​

 ​ ​ ​ ​f​u​n​c​ ​s​t​a​r​t​O​b​s​e​r​v​i​n​g​E​m​p​l​o​y​e​e​(​e​m​p​l​o​y​e​e​:​ ​E​m​p​l​o​y​e​e​)​ ...

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