Pointer Variables and Object Ownership

Pointer variables imply ownership of the objects that they point to.

  • When a method (or function) has a local variable that points to an object, that variable is said to own the object being pointed to.

  • When an object has an instance variable that points to another object, the object with the pointer is said to own the object being pointed to.

Think back to your RandomItems application. In this application, an instance of NSMutableArray is created in main() and then ten BNRItem instances are added to it. Figure 3.2 shows some of the objects in RandomItems and the pointers that reference them.

Figure 3.2  RandomItems object diagram (with only two items)

Within main() ...

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.