Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Blog Reader iPhone App Data Modeling Creating a Custom Class: Part 2

Parend/Child Relationship

What are some examples of a Parent->Child and Child->Parent relationship?

1 Answer

Rutger Farry
Rutger Farry
10,722 Points

Probably the most common Parent->child relationship in iOS is the View Controller->View relationship. The View Controller retains a pointer to its view so that it can update it when necessary. Parent-Child relationships are much more common, as they follow from writing encapsulated code. Sometimes a Child->Parent relationship is useful, but usually should be avoided, as this means that your child class must know information about its parent, which can result in a confusing web of dependancies. A better option is to use delegation or notifications, which you should learn about later.

Just remember that parents should maintain a strong reference to their children, while children should use a weak reference to their parent. Failure to observe this will result in memory leaks.