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: More on Key-Value Observing

How did the label become an observer of the temperature key in the MainWindowController object? The code to become an observer of this key might look something like this:

l​e​t​ ​m​a​i​n​W​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​ ​=​ ​.​.​.​
m​a​i​n​W​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​.​a​d​d​O​b​s​e​r​v​e​r​(​s​e​l​f​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​f​o​r​K​e​y​P​a​t​h​:​ ​"​t​e​m​p​e​r​a​t​u​r​e​"​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​o​p​t​i​o​n​s​:​ ​N​S​K​e​y​V​a​l​u​e​O​b​s​e​r​v​i​n​g​O​p​t​i​o​n​s​.​O​l​d​,​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​c​o​n​t​e​x​t​:​ ​&​M​y​K​V​O​C​o​n​t​e​x​t​)​

This method is defined in NSObject. It is how you say, Hey! Let ...

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