What is the strong property attribute

IphoneObjective CIosCocoaMacos

Iphone Problem Overview


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

Iphone Solutions


Solution 1 - Iphone

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

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChance HudsonView Question on Stackoverflow
Solution 1 - IphoneLily BallardView Answer on Stackoverflow
Solution 2 - IphoneJack FarnandishView Answer on Stackoverflow
Solution 3 - Iphonesanjeev sharmaView Answer on Stackoverflow