IBOutlet should be weak?

automatic-ref-counting, iboutlet, ios, iphone

Solution

For a discussion of why `IBOutlet` references should be weak, see the Resource Programming Guide: Nib Files. I quote from the guide:

Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong. Outlets that you create should therefore typically be weak, because:

- Outlets that you create to subviews of a view controller’s view or a window controller’s window, for example, are arbitrary references between objects that do not imply ownership.

- The strong outlets are frequently specified by framework classes (for example, `UIViewController`’s view outlet, or `NSWindowController`’s window outlet).

For my own two cents, I make things `strong` if I own it, or I need a strong reference in case the owner goes away and I need it to be retained, neither of which apply here. So, rather than asking, "why can't I make it `strong`?", I'd ask "why would I want to make it `strong`?" If there's no good reason to do so, I'd let Interface Builder do it's thing and make it `weak`.

Problem

Possible Duplicate: Should IBOutlets be strong or weak under ARC? I read about ARC briefly and thought ok, everything is strong and delegate is weak. Now I'm creating a view in interface builder and making IBOutlets, and Xcode's default setting is set to weak. There seems to be a reason for this suggestion, is there a reason most IBOutlets would want weak property? Is that because these views(IBOutlets) are already retained because they are attached to its superview? and we seldom replace IBOutlet views? But I don't see a harm in setting it as strong, is there a problem with it?

Original source

Related problems