Reputation: 17132
I have the following code to handle a swipe gesture.
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Right) {
print("Swipe Right")
self.performSegueWithIdentifier("eventsModally", sender: self)
}
}
What is the best practise to make this method available in the whole project, instead of implementing it in every ViewController class?
Help is very appreciated.
Upvotes: 4
Views: 66
Reputation: 9319
Put it in a class extension.
extension UIViewController {
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Right) {
print("Swipe Right")
self.performSegueWithIdentifier("eventsModally", sender: self)
}
}
}
Upvotes: 6