Created
March 24, 2023 21:57
-
-
Save timonus/624bf04c9b596604c82ee03c98250f7c to your computer and use it in GitHub Desktop.
Swift Leak Playground
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
// | |
// ViewController.swift | |
// Playground | |
// | |
// Created by Tim Johnsen on 3/24/23. | |
// | |
import UIKit | |
class MyObject { | |
var block: ((UIButton) -> Void)? = nil | |
var button: UIButton? = nil | |
func setup() { | |
button = UIButton() | |
block = { /*[weak self]*/ button in // Try toggling this on and off and looking for the "DEALLOCATING" log line | |
button.addAction(UIAction { [weak self] _ in | |
self?.doSomething() | |
}, for: .touchUpInside) | |
} | |
} | |
func doSomething() { | |
} | |
deinit { | |
print("DEALLOCATING") | |
} | |
} | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let obj = MyObject() | |
obj.setup() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment