Xcode4 - Declaring an object in header file
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 c开发者_如何学Pythonode 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
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
In the second example you only declare a property. Xcode will declare object automatically.
精彩评论