Skip to content

Instantly share code, notes, and snippets.

@yoman07
Created May 20, 2017 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoman07/7aae5abb957ff656b2f118ad1e6c2d36 to your computer and use it in GitHub Desktop.
Save yoman07/7aae5abb957ff656b2f118ad1e6c2d36 to your computer and use it in GitHub Desktop.
import UIKit
final class Action: NSObject {
private let _action: () -> ()
init(action: @escaping () -> ()) {
_action = action
super.init()
}
func action() {
_action()
}
}
extension UIView {
func tap(numberOfTapsRequired: Int = 1, action: Action) {
let tapRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: action, action: #selector(action.action))
tapRecognizer.numberOfTapsRequired = numberOfTapsRequired
addGestureRecognizer(tapRecognizer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment