views:

27

answers:

1

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)

// VERSION 2.0
@interface Planet : NSObject
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSNumber *mass;

-(NSString *)description;
@end

gary.

+1  A: 

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.

nacho4d
Thank you, both versions work in Xcode 3.2.3 but you need to add @synthesize to both. It also looks like Xcode 4 will do away with the @synthesize too. Many thanks for the help, its much appreciated.
fuzzygoat