美文网首页
Swift与OC差异 - 基础概念

Swift与OC差异 - 基础概念

作者: FansX | 来源:发表于2018-11-23 14:48 被阅读0次
弱引用、强引用
  • 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
}()

相关文章

网友评论

      本文标题:Swift与OC差异 - 基础概念

      本文链接:https://www.haomeiwen.com/subject/jctjqqtx.html