
说IT
用代码摇滚这个世界
一个关注技术与人文的IT博客
一、关于objective-C的属性,常见的有:strong、weak、copy、assign
- 对于基本数据类型,当然使用assigin;
- 对于mutable的,一定要使用strong。父控件UI元素也使用strong;
- 子控件元素使用weak;
- 不可变的类型,使用copy。(NSString,NSArray,NSDictonary这些一定要用copy)对于mutable的对象,如果是mutable的却定义属性为copy,则往里面加值时可能引起程序崩溃。而对于不可变的使用了strong,则可能引起值改变,这就违背了内存管理语义
二、关于getter


1 2 3 4 5 6
| if (_messageTipNumber > 0) { self.tipCountLable.frame = CGRectMake(150, (self.frame.size.height - 14)/2, 14, 14); self.tipCountLable.layer.cornerRadius = _tipCountLable.frame.size.width/2; self.tipCountLable.text = [NSString stringWithFormat:@"%d",_messageTipNumber]; [self.contentView addSubview:_tipCountLable]; }
|
本文代表个人观点,内容仅供参考。若有不恰当之处,望不吝赐教!