I am doing some processing of network requests, and the response is processed in a background thread using a closure.
The closure executes some logic on the background thread and then (possibly) dispatched to the main thread. Something like
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?
My thought is that I need both because it is possible that by the time the main-thread code executes, the object referred to by "self" might have been deallocated. (Unlikely, but conceivable.)
Am I thinking about this correctly??
Thanks.