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 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.