UIControlExtensions.swift 416 B

1234567891011121314
  1. //
  2. // SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import Foundation
  6. extension UIControl {
  7. // See: https://stackoverflow.com/a/41438789
  8. func addAction(for controlEvents: UIControl.Event = .touchUpInside, _ closure: @escaping () -> Void) {
  9. addAction(UIAction { (action: UIAction) in closure() }, for: controlEvents)
  10. }
  11. }