简体   繁体   中英

Difference between Strong and Weak IBOutlets

What is the difference between strong and weak IBOutlets in the Xcode iOS 5.1 SDK?

I was previously using the 4.3 SDK, where strong IBOutlets did not exist. In addition, (auto)release is not available in the iOS 5.1 SDK.

Strong means that as long as this property points to an object, that object will not be automatically released. In non-ARC it's a synonym for retain

Specifies that there is a strong (owning) relationship to the destination object.

Weak instead, means that the object the property points to, is free to release but only if it sets the property to NULL. In ARC you use weak to ensure you do not own the object it points to

Specifies that there is a weak (non-owning) relationship to the destination object. If the destination object is deallocated, the property value is automatically set to nil.

Nonatomic means that if multiple threads try to read or to change the property at once, badness can happen. Consequences are that there will be partially-written values or over-released objects = CRASH.

Take also a look here, at Apple's documents .

From there, examples are

@property (weak) IBOutlet MyView *viewContainerSubview;
@property (strong) IBOutlet MyOtherClass *topLevelObject;

Check also this to know more about strong and weak .

In ARC (Automatic Reference Counting) Strong tells the compiler that the property-owner relationship is "strong". It is equivalent to retain in the autorelease pool memory scheme. Apple has a article on transitioning to ARC here .

The property which you declare as a strong , it owns the object and the compiler will take care that which any object assigns this property. This property will destroyed when we set to nil.

When you don't want the control life time then u declare as a week property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM