How do you declare IBOutlets?

Discussion in 'iOS Programming' started by MacMan988, Apr 1, 2014.

  1. MacMan988 macrumors 6502a

    Jul 7, 2012
    What is the difference between declaring IBOutlets as


    @interface FooController : UIViewController {
        IBOutlet UILabel *fooLabel;


    @interface FooController : UIViewController 
    @property (nonatomic, retain) IBOutlet UILabel *fooLabel;

    Does it have to include the @property keyword when declaring IBOutlets? How do you declare them?
  2. Menneisyys2 macrumors 603

    Jun 7, 2011
    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.”

    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.

Share This Page