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
Harry Stromfelt
2,985 Pointsretain vs assign vs strong vs weak... vs whatever else there is?! D:
Could someone explain what is the difference between the @property (nonatomic, retain/assign/...)? I am writing an app and have basically just made everything strong, because I don't know how to decide!
Thank you Harry
1 Answer
Patrick Cooney
12,216 PointsThat stuff relates to memory management. atomic and nonatomic have to do with multithreading. atomic makes it so that the whole value is read at once. nonatomic does not guarantee that you will get the entire value back. retain is the old version of strong. You're telling the system to keep that property around until you let it go (in the case of retain) or the system determines it no longer needs it (in the case of strong). The rule of thumb is that if you have an object that relies on another object to exist you should make that property/object weak. For instance UI elements are usually weak because if you no longer have an instance of UIView or UIViewController that they're attached to that probably means you don't need them anymore.
Harry Stromfelt
2,985 PointsHarry Stromfelt
2,985 PointsThank you. What is a likely problem that may occur if you were to set a 'weak' property where 'strong' was needed?
Patrick Cooney
12,216 PointsPatrick Cooney
12,216 PointsYou run the risk of that object no longer being around. It could (it isn't guaranteed to happen) get deallocated in which case you would get a runtime error because the object no longer exists.