Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Using Parse.com as a Backend and Adding Users Signing Up New Users: Part 1 (UIAlertView)

Why do we make SignUpViewContorller's text field's weak?

In previous app's we always made the text fields have the strong property but in this video, it was not clear to me why we made the text fields weak.

2 Answers

Stone Preston
Stone Preston
42,016 Points

also see this for a very good overview of ARC and strong vs weak. the diagrams help a lot.

Stone Preston
Stone Preston
42,016 Points

you use the weak attribute when you have a parent child relationship. The text fields superView has a strong pointer to its subviews and its subviews will be retained as long as the superview exists, so you dont need to use strong for the outlet as well. If you did you would have whats known as a retain cycle (the textfield would continue to exist in memory even though its parent view is gone) . You generally use weak for all outlets since they are part of a parent child relationship.

It wouldn't be a retain cycle, the view would just dangle if the ViewController persisted in memory while its view did not. That won't happen in iOS 7 though, since a ViewController will keep it's view alive.