Assigning a IBOutlet in Objective-C

Casebash picture Casebash · Jan 21, 2010 · Viewed 7.5k times · Source

The code generator Accessorizer has an option to assign IBOutlets rather than retaining them. For example, compare these two generated lines:

@property(nonatomic,retain)IBOutlet UIImageView *backgroundView;
@property(nonatomic,assign)IBOutlet UIImageView *backgroundView;

Why would I want to assign IBOutlets, while retaining all other properties?

Answer

Tyr picture Tyr · Jan 23, 2010

Usage depends on the platform as specified in the memory management guide :

"The behavior of outlets depends on the platform (see “Mac OS X Desktop” and “iPhone”), so the actual declaration differs:

  For Mac OS X, you should use:

  @property (assign) IBOutlet UserInterfaceElementClass *anOutlet;

  For iPhone OS, you should use:

  @property (nonatomic, retain) IBOutlet UIUserInterfaceElementClass *anOutlet;"