简体   繁体   中英

Do we need to worry about weak self inside methods called from closures

Trivial but looking for confirmation I'm understanding correctly:

If we have a simple closure as so:

let closure = { [weak self] in 
    self?.doSomething()
}

Do we need to worry about weak/strong self within the method itself?

func doSomething() {
    self.classString = "some new string" 
    // the self in this case will come from the weak self in the closure?
}

The following as I understand is unnecessary even though it'll be called from a closure:

func doSomething() {
    weak var weakSelf = self
    weakSelf.classString = "some new string" 
}

不,我们不必担心,因为一种方法无法捕获任何东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM