Key paths

Most applications end up with a relatively complex object graph. For example, you might have a BNRDepartment object that has a manager property that is a pointer to an BNREmployee object which has an emergencyContact property which is a pointer to a BNRPerson object which has a phoneNumber property.

Figure 35.1  Complex object graph

Complex object graph

Imagine that you are asked, What is the phone number of the emergency contact for the manager of the sales department? You could use key-value coding to traverse these relationships one at a time:

B​N​R​D​e​p​a​r​t​m​e​n​t​ ​*​s​a​l​e​s​ ​=​ ​…​;​ B​N​R​E​m​p​l​o​y​e​e​ ​*​s​i​c​k​E​m​p​l​o​y​e​e​ ...

Get Objective-C 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.