Adding a closure as target to a UIButton

With iOS 14 Apple has finally added this feature to UIKit. However, someone might still want to use this extension because Apple’s method signature is suboptimal. iOS 14: extension UIControl { func addAction(for controlEvents: UIControl.Event = .touchUpInside, _ closure: @escaping()->()) { addAction(UIAction { (action: UIAction) in closure() }, for: controlEvents) } } pre-iOS 14: extension … Read more