美文网首页
Swift 中的weakSelf

Swift 中的weakSelf

作者: 大也 | 来源:发表于2021-08-13 08:46 被阅读0次
// 第一种写法
request.responseString(encoding: NSUTF8StringEncoding) {[weak self] (res) -> Void in
   if let strongSelf = self {
       //do something...
   }
} 
weak var weakSelf = self
request.responseString(encoding: NSUTF8StringEncoding) {(res) -> Void in
   if let strongSelf = weakSelf {
       //do something
   }
}  

Swift内存泄漏详解([weak self]使用场景)
https://www.jianshu.com/p/cb45b5e016ff

相关文章

网友评论

      本文标题:Swift 中的weakSelf

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