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 Diary App Using Core Data Custom Detail View Controller Implementing a UITextView

Tommy Choe
Tommy Choe
38,156 Points

Not entirely sure when to use strong vs. weak

On the quiz, this statement is marked as true: "Since our view controller’s view doesn’t own the accessory view, its property should be strong."

First, what does it mean when something owns something else? Is it referring to subclassing?

Secondly, I don't understand why its property would be strong if the view controller didn't own the accessory view. Isn't that more of a reason for a reference to be weak not strong since you would want the reference to be cleared as soon as accessory view goes away?

1 Answer

When they are saying it is "owned" I believe that they simply mean that something is pointing to it. Something is owned when it is allocated, retained, or copied.

Strong means that you want to own the actual object (you create it and maintain it until it is no longer needed) vs weak where you are saying "Hey I don't want to be in control of the life of this object, let someone else decide when it needs to go away", another object will reference it until it is no longer needed.

Could you share the code for your second question, if possible? I'm guessing that the view shouldn't be deallocated which is why it is set to strong, so that there is always a reference in memory.

Tommy Choe
Tommy Choe
38,156 Points

Ok thank you for the clarification. Sorry, I don't have any code associated with my question. It was part of a teamtreehouse quiz.