In Swift, When using [weak self] in
, should I double up on it when nested inside another closure.
Example:
override func viewDidLoad() {
super.viewDidLoad()
makeAPICall() { [weak self] in
self?.finishedAPICall = true
DispatchQueue.main.async { [weak self] in
// random code with self
self?.view.layoutIfNeeded()
}
}
}
func makeAPICall(completion: () -> Void) {}
The outermost [weak self]
makes all the following self's optional no matter what. Does this mean that it is handling holding it in memory inside of the nested closures all the way through as well? If I am using self in both areas, do I need it in both?