Possible Duplicate:
Properties and Instance Variables in Objective-C 2.0
I'm confused by these two code segments:
First:
//.h
@interface Student : NSObject {
}
@property (nonautomic, copy) NSString *name;
@property (nonautomic, retain) NSNumber *age;
@end
//.m
@implementation Student
@synthesize name;
@synthesize age;
@end
Second:
//.h
@interface Student : NSObject {
NSString *name; // <<============ difference
NSNumber *age; // <<============ difference
}
@property (nonautomic, copy) NSString *name;
@property (nonautomic, retain) NSNumber *age;
@end
//.m
@implementation Student
@synthesize name;
@synthesize age;
@end
Both of these can work. So is it necessary to declare variables in the {}
?
Starting with the modern runtime (x86_64 and ARM6...and iOS Simulator) you no longer need to declare synthesized ivars. In the first example @synthesize is adding the instance variable for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With