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 ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.