假设将synthesize省略,而且我们自己实现setter和getter方法时,系统就不会生成相应的setter和getter方法,还有实例变量
1,当把语义特性声明为assign时,setter和getter时方法内部实现
_name = name;
}
- (NSString *)name{
return _name;
}
2,当把语义特性声明为retain时,setter和getter方法内部实现
- (void)setName:(NSString *)name{
if (_name != name) {
[ _name release];
_name = [name retain];
}
}
- (NSString *)name{
return [[ _name retain] autorelease];
}
3,当把语义特性声明为copy时,setter和getter方法内部实现
- (void)setName:(NSString *)name{
if (_name != name) {
[ _name release];
_name = [name copy];
}
}
- (NSString *)name{
return [[ _name retain] autorelease];
}