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!
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
Nic HuangCourses Plus Student 10,573 Points
property use, strong or weak ???
I just finished the second video "Creating a Custom Class - Part 2" in building BlogReader. The video states that we should use property "strong" in "parent to child relationship", and "weak" in "child to parent relationship" when we are creating property.
But how do you define "parent to child relationship" and "child to parent relationship"??
any good example ???
appreciate your help.
Amit BijlaniTreehouse Guest Teacher
The easiest way to explain is by way of an example. When you create a
UITableViewController you have a main property pointing to the
tableView which would be of type
strong. However, the
tableView has two property
datasource both of which are protocols that define methods. However, these methods are defined in the
tableView's parent class which is the table view controller.
Here's a diagram illustrating the above example:
In the simplest of cases you use a strong relationship to keep something alive, and a weak relationship when something (that is being kept alive by something else) needs to refer back to what is keeping it alive.
A view controller has a view, that view is being kept alive by the view controller (the view controller has a strong relationship to it) but the view may want to communicate with its view controller. So that view could have a weak relationship to the view controller.