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
To get the selected person’s spouse’s scooter’s model name, you can use a key path:
let modelName = selectedPerson.valueForKeyPath("spouse.scooter.modelName") as String
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.