![](/img/trans.png)
[英]Do capture lists of inner closures need to redeclare `self` as `weak` or `unowned`?
[英]Do we need to worry about weak self inside methods called from closures
琐碎,但正在寻找确认,我正确理解了:
如果我们有一个简单的闭包:
let closure = { [weak self] in
self?.doSomething()
}
我们是否需要担心方法本身内部的弱/强自我?
func doSomething() {
self.classString = "some new string"
// the self in this case will come from the weak self in the closure?
}
据我了解,以下内容是不必要的,即使会从闭包中调用它:
func doSomething() {
weak var weakSelf = self
weakSelf.classString = "some new string"
}
不,我们不必担心,因为一种方法无法捕获任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.