@chenbinghua
2015-09-12T10:29:03.000000Z
字数 530
阅读 2860
iOS技巧
首先看一下代码
@interface ViewController ()
{
NSString *_name;
}
@property (nonatomic, copy) NSString *name;
@end
1.速度快
_name = @"小明";
2.设置标志变量
@interface ViewController ()
{
BOOL _flag;
}
1.设置readonly
2.过滤不合适的值
self.age = -1; //age = 0;
-(void)setAge:(NSInteger)age
{
if (age <= 0 && age >= 300) {
age = 0;
}
_age = age;
}
3.当值发生改变时发出通知
-(void)setCityID:(NSString *)cityID
{
if (_cityID != cityID) {
// 发出通知
}
_cityID = cityID;
}