Last active
April 13, 2021 12:13
-
-
Save Thomvis/97212c65ce84541f63f2a1e3e903c407 to your computer and use it in GitHub Desktop.
Capturing a weak reference to self in a nested closure could cause a retain cycle. `[weak self]` weakly captures self from the outer closure. Since the outer closure did not declare a weak reference to self, it will keep a strong one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewModel { | |
let intGetterGetter: () -> () -> Int? | |
var currentInt = 2 | |
init() { | |
self.intGetterGetter = { | |
return { [weak self] in | |
return self?.currentInt | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment