modern API of UIButton

Here’s the code if you want to experiment with it!

class ViewController: UIViewController {

    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var button: UIButton!

    var counter = 0 {
        didSet {
            label.text = "Counter: \(counter)"
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        button.addAction(UIAction { [weak self] _ in
            self?.counter += 1
        }, for: .touchUpInside)
    }
}
Previous
Previous

Combine nested if

Next
Next

XCTUnwrap vs force unwrap