O'Reilly logo

Objective-C Programming: The Big Nerd Ranch Guide by Mikey Ward, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

23 Preventing Memory Leaks

It is pretty common to have relationships that go in two directions. For example, maybe an asset should know which employee is currently holding it. Let’s add that relationship. The new object diagram would look like this:

Figure 23.1  Adding holder relationship

Adding holder relationship

From a design standpoint, you would say that you are adding a pointer from the child (an instance of BNRAsset) back to its parent (the instance of BNREmployee that is holding it).

In BNRAsset.h, add a pointer instance variable to hold on to the holding employee:

#​i​m​p​o​r​t​ ​<​F​o​u​n​d​a​t​i​o​n​/​F​o​u​n​d​a​t​i​o​n​.​h​>​
@​c​l​a​s​s​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required