How do you declare IBOutlets?

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

  1. MacMan988 macrumors 6502a

    Joined:
    Jul 7, 2012
    #1
    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?
     
  2. Menneisyys2 macrumors 603

    Joined:
    Jun 7, 2011
    #2
    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.
     

Share This Page