2014年3月8日 星期六

@property and @synthesize

@property auto create getter and setter for the variable

e.g. declaration in "Student.h"

@interface Student: NSObject;
{
   NSString *name;
}

-(void) setName: NSString *name;
-(NSString *)getName;

@end

By using @property, getter and setter can be saved:

@interface Student: NSObject;
{
   NSString *name;
}
@property NSString *name;

@end

Then in implementation "Student.m"

@implementation Student

@synthesize name;   //can omit for iOS4.4+

@end

@synthesize here is actually telling the compiler to auto generate the code for getter and setter.

沒有留言:

張貼留言