2

For example one, I declare an object inside the interface brace {} like:

@interface testViewController : UIViewController {
    IBOutlet UILabel * myLabel;
}
@property (retain, nonatomic) UILabel *myLabel;

@end

and example two, I declare an object outside the inferface brace {} like:

@interface testViewController : UIViewController {
}
@property (retain, nonatomic) IBOutlet UILabel *myLabel;

@end

I run the code and the result is the same, so I want to ask what is the different for decalare an object inside or outside the interface brace {}?

Thanks

Charles Yeung
  • 38,347
  • 30
  • 90
  • 130
  • possible duplicate of [Declaring IBOutlet inside or outside @interface?](http://stackoverflow.com/questions/4635190/declaring-iboutlet-inside-or-outside-interface) – Abizern Aug 06 '11 at 08:32
  • Here is your **[solution..**](http://stackoverflow.com/questions/4635190/declaring-iboutlet-inside-or-outside-interface "Declaring IBOutlet inside or outside @interface?") – alloc_iNit Aug 06 '11 at 08:26

2 Answers2

1

The modern Objective-C runtimes (64-bit Mac OS X and iOS) will generate the backing store for your declared properties when you @synthesize them. So you don't need to declare them within the braces.

If you are declaring an iVar that is not a property and will only be used by the class, then they need to be declared. It's a good idea to mark these @private e.g

@interface MyClass : NSObject {
@private
    NSString *privateString;
}
@property (nonatomic, copy) NSString *publicString; // be sure to @synthesize this
@end
Abizern
  • 146,289
  • 39
  • 203
  • 257
0

In the second example you only declare a property. Xcode will declare object automatically.

unknown
  • 94
  • 3