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 {}
?