For the More Curious: Key Paths

Objects are often arranged in a network. For example, a person might have a spouse who has a scooter that has a model name (Figure 8.14).

Figure 8.14  Directed graph of objects

Directed graph of objects

To get the selected person’s spouse’s scooter’s model name, you can use a key path:

l​e​t​ ​m​o​d​e​l​N​a​m​e​ ​=​ ​s​e​l​e​c​t​e​d​P​e​r​s​o​n​.​v​a​l​u​e​F​o​r​K​e​y​P​a​t​h​(​"​s​p​o​u​s​e​.​s​c​o​o​t​e​r​.​m​o​d​e​l​N​a​m​e​"​)​ ​a​s​ ​S​t​r​i​n​g​

We would say that spouse and scooter are relationships of the Person class and that modelName is an attribute of the Scooter class.

There are also operators that you ...

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.