Swift 中的weakSelf
2021-08-13 本文已影响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