Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacMan988

macrumors 6502a
Original poster
Jul 7, 2012
895
176
What is the difference between declaring IBOutlets as

FooController.h:

Code:
@interface FooController : UIViewController {
    IBOutlet UILabel *fooLabel;
}

@end


and

Code:
@interface FooController : UIViewController 

@property (nonatomic, retain) IBOutlet UILabel *fooLabel;

@end


Does it have to include the @property keyword when declaring IBOutlets? How do you declare them?
 
What is the difference between declaring IBOutlets as ...Does it have to include the @property keyword when declaring IBOutlets? How do you declare them?

1. While,
- if you use ARC and
- don't reassign references (to, say, a, from your app, dynamically instantiated widget) and
- you don't try to compile it with the long-abandoned (but, as of Xcode 4.4, still selectable), for iOS compilation, pretty much useless GCC,

there's no real difference between the two approaches, Apple still recommends using properties:

“From a practical perspective, in iOS and OS X outlets should be defined as declared properties. 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.”

https://developer.apple.com/library...bs.html#//apple_ref/doc/uid/10000051i-CH4-SW6

That is, while ivars do work, use properties instead.

2. You don't have to manually create their full declaration - just drag in the Assistant editor from the XIB to the VC.h and you're set - except for the property name, everything will be auto-filled-in.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.