pflous
pflous

Reputation: 571

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" 
}

Upvotes: 0

Views: 40

Answers (1)

vadian
vadian

Reputation: 285079

No we don't need to worry because a method is not capturing anything.

Upvotes: 2

Related Questions