object interface layout?
Previously I used to write my object interfaces like this:
// VERSION 1.0
@interface Planet : NSObject {
NSString *name;
NSString *type;
NSNumber *mass;
}
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSNumber *mass;
-(NSString *)description;
@end
But I have noticed recently that I can also write them like this. I am guessing that the removal of the iVars is a new feature that has been added to Xcode recently. Am I right in thinking that I should be looking towards using VERSION 2.0 (although I do find the earlier version more readable at the expense of the extra typing)
// VER开发者_StackOverflow社区SION 2.0
@interface Planet : NSObject
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSNumber *mass;
-(NSString *)description;
@end
gary.
With new Xcode, writing Objective-C is becoming easier and shorter but what it really does is just add the ivars or synthesized properties behind the scenes I believe. (Yeah, in xcode 4 properties are synthesized by default) The real way is VERSION 1.0. , version number two is just an abbreviated version one that I am not sure It will work without Xcode. Xcode is changed but the Language specification is not, I believe. I hope this helps.
精彩评论