@propert和@@synthesize的含义与区别
一 含义
@property是在头文件.h中声明一个变量的setter和getter方法。
@synthesize是在m文件中定义setter和getter方法的实现。
二 区别
在 .h文件中
@property声明
例如:
@property NSString *testStr;
在.m文件里直接使用
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
self.testStr=@"aaaa";
// Dispose of any resources that can be recreated.
}
或者在.m文件里使用
@synthesize testStr;
可以使用
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
testStr=@"aaaa";
// Dispose of any resources that can be recreated.
}
最后他们是等价的。