Last active
December 20, 2018 08:00
-
-
Save muyexi/2e189fc8fc558f286783e11de8e8bbd3 to your computer and use it in GitHub Desktop.
Implicit retain cycle in lazy var
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 API { | |
var status: String? | |
var failureHandler: (() -> Void)? | |
var completionHandler: (() -> Void)? | |
init() {} | |
} | |
class ViewController: UIViewController { | |
lazy var api: API = { | |
let api = API() | |
api.completionHandler = { | |
} | |
api.failureHandler = { | |
// `api` reference Cause retian cycle | |
// Use `self.api` instead of 'api' to fix it | |
print(api.status ?? "") | |
} | |
return api | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment