Without a property (in iOS) the IBOutlet will be ivar is set and retained by KVC. With a @property
the ivar is set by setting the property.
On an ARC project, if one creates a nib and drags an item (say UILabel
) to the .h file a strong @property
will be added as well as in the .m file a line setting the property to nil will be added to the viewDidUnload
method and a @synthesize statement for the property.
There are other ways to handle the retaining of nib
IBOutlets
that work and may even be better by some metric.
From the Apple document Resource Programming Guide - Managing the Lifetimes of Objects from Nib Files:
Because the behavior of outlets depends on the platform, the actual
declaration differs:
For iOS, you should use:
@property (nonatomic, retain) IBOutlet UserInterfaceElementClass *anOutlet;
For OS X, you should use:
@property (assign) IBOutlet UserInterfaceElementClass *anOutlet;
My belief is to not fight the way Apple does things, doing so tends to make things harder. Also consider that Apple has inside information of the future of the platform. :-)
unsafe_unretained
? In iOS (as opposed to OS X) IBOutlets should be retained. – zaphOutlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership.
. – Paul.s