Last active
June 13, 2018 16:07
-
-
Save nkukushkin/cdba791333fcdaf47da2 to your computer and use it in GitHub Desktop.
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
import UIKit | |
class ViewController: UIViewController { | |
func doSomething() {} | |
func howDoesThisWork() { | |
// Nested function that references `self` implicitly. | |
func performDoSomething() { | |
doSomething() | |
} | |
dispatch_async(dispatch_get_main_queue()) { [weak self] in | |
// When we call `doSomething()` compiler asks us to explicitly add `self` to the call. | |
self?.doSomething() | |
// However, when we call the nested function it doesn't. | |
// And the behaviour is ambiguous (probably retains `self`). | |
performDoSomething() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/jckarter/status/697100492288057345