Created
May 19, 2017 21:15
-
-
Save efremidze/2f7fae290e5b52ec33a9943ac7b87a8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private var targets = [Target]() | |
extension UIGestureRecognizer { | |
convenience init(action: @escaping (UIGestureRecognizer) -> ()) { | |
self.init() | |
addAction(action) | |
} | |
func addAction(_ action: @escaping (UIGestureRecognizer) -> ()) { | |
let target = Target(action) | |
targets.append(target) | |
addTarget(target, action: #selector(target.invoke)) | |
} | |
} | |
private class Target { | |
private let closure: (UIGestureRecognizer) -> () | |
init(_ closure: @escaping (UIGestureRecognizer) -> ()) { | |
self.closure = closure | |
} | |
@IBAction func invoke(_ recognizer: UIGestureRecognizer) { | |
self.closure(recognizer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment