弱引用、强引用
- OC
__weak typeof(self) weakSelf = self
__strong typeof(weakSelf) strongSelf = weakSelf // 用于弱引用可能在闭包中销毁self的情况
- Swift
[weak self]
guard let strongSelf = self else { return } // 用于弱引用可能在闭包中销毁self的情况
懒加载
- OC
-(UILabel*)nickLabel {
if(nickLabel == nil) {
UILabel *nick = [[UILabel alloc] init];
}
return nick;
}
- Swift
lazy var nickLabel: UILabel = {
let nick = UILabel()
return nick
}()