7

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.

royhowie
  • 11,075
  • 14
  • 50
  • 67
Dinesh
  • 6,500
  • 10
  • 42
  • 77
  • You can't compare strong and nonatomic. I think you mean the difference between strong and weak. Have you tried to read something about it in the Apple docs? – dasdom Jun 23 '12 at 11:12
  • @dasdom ok weak and strong reference differences guided me or any document link – Dinesh Jun 23 '12 at 11:13
  • Autorelease and release are available in iOS 5 if you disable ARC. ARC is a feature that can be enabled or disabled. – borrrden Jun 23 '12 at 11:20
  • possible duplicate of [Should IBOutlets be strong or weak under ARC?](http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc) – hypercrypt Mar 28 '13 at 17:56

3 Answers3

13

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.

NolanDC
  • 1,041
  • 2
  • 12
  • 35
Phillip
  • 4,276
  • 7
  • 42
  • 74
2

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.

doggiedoc
  • 21
  • 2
0

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.

Ganesh
  • 524
  • 1
  • 4
  • 16