Skip to content

Instantly share code, notes, and snippets.

@alexanderedge
Last active December 8, 2015 10:09
Show Gist options
  • Save alexanderedge/49ffd346e25b325fde51 to your computer and use it in GitHub Desktop.
Save alexanderedge/49ffd346e25b325fde51 to your computer and use it in GitHub Desktop.
Statically-typed functions for simple gesture recognisers
protocol Tappable : AnyObject {
func handleTap(gr : UITapGestureRecognizer)
}
extension UITapGestureRecognizer {
convenience init(target : Tappable) {
self.init(target: target, action: "handleTap:")
}
}
protocol LongPressable : AnyObject {
func handleLongPress(gr : UILongPressGestureRecognizer)
}
extension UILongPressGestureRecognizer {
convenience init(target : LongPressable) {
self.init(target: target, action: "handleLongPress:")
}
}
protocol Pannable : AnyObject {
func handlePan(gr : UIPanGestureRecognizer)
}
extension UIPanPressGestureRecognizer {
convenience init(target : Pannable) {
self.init(target: target, action: "handlePan:")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment