Created
May 20, 2017 11:04
-
-
Save yoman07/7aae5abb957ff656b2f118ad1e6c2d36 to your computer and use it in GitHub Desktop.
This file contains 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
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