Reputation: 235
This code works:
@interface StringStuff : NSObject {
}
@property (nonatomic, retain) NSString *String1;
@property (nonatomic, retain) NSString *String2;
- (NSString *) doSomethingWithStrings;
@end
But I often see:
@interface StringStuff : NSObject {
NSString *String1;
NSSTring *String2;
}
@property (nonatomic, retain) NSString *String1;
@property (nonatomic, retain) NSString *String2;
- (NSString *) doSomethingWithStrings;
@end
Is there a reason that properties are often declared as an instance variable as well? Is it just considered good form?
Upvotes: 4
Views: 122
Reputation: 162712
Legacy; it used to be (and still is on 32 bit Mac OS X targeted code) that the ivar declarations were required. That is no longer true on iOS, the simulator and 64 bit OS X.
Note that it is common to @synthesize iVar = iVar_;
to prevent accidental direct access where self.iVar
is really required.
Upvotes: 6