![](/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.