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

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.