What is the strong property attribute
I am using the Xcode beta for developers, and am noticing some subtle differences. Among them is a new attribute for declared properties.
@property(strong)IBOutlet NSArrayController *arrayControl;
My question is: what does the strong attribute mean?? Does it replace some older one, or is it something entirely new? I have searched through google and the developer documentation and havent been able to find anything. Until i know what it is i am hesitant to use it.
Thanks in advance
Solution 1:
It's a replacement for the retain
attribute, as part of Objective-C Automated Reference Counting (ARC). In non-ARC code it's just a synonym for retain
.
Solution 2:
A strong reference is a reference to an object that stops it from being deallocated. In other words it creates a owner relationship. Whereas previously you would do this:
**// Non-ARC Compliant Declaration
@property(retain) NSObject *obj;**
Under ARC we do the following to ensure a class instance takes an ownership interest a referenced object (i.e. so it cannot be deallocated until the owner is).
**// ARC Compliant Declaration
@property(strong) NSObject *obj;**
Solution 3:
As we know, we cannot release any object in an ARC-based project in iOS 5. So when we want to retain any object for further use at a later stage and don't want ARC to remove the object from memory, then we set the property for the object as "Strong".