Re: Usage Question concerning [weak self]


Ben Kennedy
 

On 23 Jun 2019, at 3:12 pm, Rick Aurbach via Groups.Io <rlaurb@...> wrote:

closure = { [weak self] (...) in
if self?.foo {
DispatchQueue.main.async { [weak self] in
self?.xxx()
}
}
}

My question is do I actually need the second "[weak self]" reference? Or, having captured self, am I ok leaving it out?
By my analysis the capture list in the DispatchQueue closure is unnecessary, because by that point `self` is already weak. You can prove this by adding a `weak var this = self` and change the `self`s to `this`es, then option-click on the inner `this` and see that it is indeed still weak.

b

Join cocoa@apple-dev.groups.io to automatically receive all group messages.