抱歉我的英语..。
在".h“文件中
NSString *_name;在".m“文件中
-(id)init{
.....
_name = [[NSString alloc] initWithString:@"Hadrian"];
.....
}以及一个用于更改_name值的函数,如下所示:
-(void) changeName:(NSString *)name{
//No 1:
_name = [name copy];
//No 2:
if(_name) [_name release];
_name = [name copy];
}没人会泄密?如何编写这个功能标准?
发布于 2013-03-26 11:12:20
Suggestions...
- Properties enforce access restrictions (such as readonly)
- Properties enforce memory management policy (retain, assign)
- Properties are (rarely) used as part of a thread safety strategy (atomic)
- Properties provide the opportunity to transparently implement custom setters and getters.
- Having a single way to access instance variables increases code readability.https://stackoverflow.com/questions/15633945
复制相似问题