Last active
September 3, 2025 18:58
-
-
Save dougboutwell/194a05fdf03751132d8dc16099bedc4a to your computer and use it in GitHub Desktop.
Retain cycles
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 ViewManager { | |
| var completion: (() -> Void)? | |
| func setup(completion: @escaping () -> Void) { | |
| self.completion = completion | |
| } | |
| } | |
| class ViewController: UIViewController { | |
| let nameLabel = UILabel() | |
| var manager = ViewManager() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| /* Setup nameLabel, etc - assume it's done sensibly */ | |
| } | |
| override func viewWillAppear() { | |
| self.function1() | |
| } | |
| func function1() { | |
| manager.setup { | |
| self.nameLabel.frame.origin.x += 100 | |
| } | |
| } | |
| func function2() { | |
| manager.setup { [weak self] in | |
| self?.nameLabel.frame.origin.x += 100 | |
| } | |
| } | |
| func function3() { | |
| manager.setup { [unowned self] in | |
| self.nameLabel.frame.origin.x += 100 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment