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

KVC and Property Accessors

KVC will call setters and getters for properties, if they are present. To see this in action, add accessors for temperature:

 ​ ​ ​ ​d​y​n​a​m​i​c​ ​v​a​r​ ​t​e​m​p​e​r​a​t​u​r​e​ ​=​ ​6​8​
 ​ ​ ​ ​p​r​i​v​a​t​e​ ​v​a​r​ ​p​r​i​v​a​t​e​T​e​m​p​e​r​a​t​u​r​e​ ​=​ ​6​8​
 ​ ​ ​ ​d​y​n​a​m​i​c​ ​v​a​r​ ​t​e​m​p​e​r​a​t​u​r​e​:​ ​I​n​t​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​s​e​t​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​l​n​(​"​s​e​t​ ​t​e​m​p​e​r​a​t​u​r​e​ ​t​o​ ​\​(​n​e​w​V​a​l​u​e​)​"​)​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​p​r​i​v​a​t​e​T​e​m​p​e​r​a​t​u​r​e​ ​=​ ​n​e​w​V​a​l​u​e​
 ​ ​ ​ ​ ​ ​ ​ ​}​
 ​ ​ ​ ​ ​ ​ ​ ​g​e​t​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​l​n​(​"​g​e​t​ ​t​e​m​p​e​r​a​t​u​r​e​"​)​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​r​e​t​u​r​n​ ​p​r​i​v​a​t​e​T​e​m​p​e​r​a​t​u​r​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