For the More Curious: Key-Value Coding

When a NIB file is read in, the outlets are set using a mechanism called Key-value coding (or KVC). Key-value coding is a set of methods defined in NSObject that enable you to set and get the values of properties by name. Here are two of the methods:

-​ ​(​i​d​)​v​a​l​u​e​F​o​r​K​e​y​:​(​N​S​S​t​r​i​n​g​ ​*​)​k​;​
-​ ​(​v​o​i​d​)​s​e​t​V​a​l​u​e​:​(​i​d​)​v​ ​f​o​r​K​e​y​:​(​N​S​S​t​r​i​n​g​ ​*​)​k​;​

valueForKey: is a universal getter method. You can ask any object for the value of its fido property like this:

i​d​ ​c​u​r​r​e​n​t​F​i​d​o​ ​=​ ​[​s​e​l​e​c​t​e​d​O​b​j​ ​v​a​l​u​e​F​o​r​K​e​y​:​@​"​f​i​d​o​"​]​;​

If there is a fido method (the fido-specific getter), it will be called and ...

Get iOS Programming: 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.