The difference between strong and weak IBOutlets

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

Earlier, I used the 4.3 SDK, where there were no strong IBOutlets. In addition, the (automatic) version is not available in iOS 5.1 SDK.

+7
source share
3 answers

Strong means that while this property points to an object, this object will not be automatically freed. In non-ARC, it's synonymous with retain

Indicates that there is a strong (owning) relationship with the target.

Weak instead means that the object that the property points to is freed, but only if it sets the property to NULL. In ARC, you use weak to make sure you donโ€™t own the object that it points to

Indicates that there is a weak (non-owning) connection with the target. If the target is freed, the property value is automatically set to zero.

Nonatomic means that if multiple threads try to read or change a property at once, bad things can happen. The consequences are that there will be partially recorded values โ€‹โ€‹or re-issued objects = CRASH.

Look here in the Apple docs .

From there examples

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

Also check this one to learn more about Strong and Weak .

+10
source

In ARC (automatic reference counting), Strong tells the compiler that the property ownerโ€™s relationship is strong. This is equivalent to retain in the memory map of the abstract pool. Apple has an article on switching to ARC here .

+2
source

A property that you declare as strong, it owns the object, and the compiler takes care that any object assigns this property. This property will be destroyed when we set to zero.

If you do not need the lifetime of the control, then declare it as a property of the week.

0
source

All Articles