How to make an accessible method throughout the project

I have the following code for handling swipe gestures.

    func handleSwipes(sender:UISwipeGestureRecognizer) {

    if (sender.direction == .Right) {
        print("Swipe Right")
        self.performSegueWithIdentifier("eventsModally", sender: self)
    }
}

What is the best practice to make this method available throughout the project, rather than embed it in every ViewController class?

Help is greatly appreciated.

+4
source share
1 answer

Put it in the extension.

extension UIViewController {
    func handleSwipes(sender:UISwipeGestureRecognizer) {
        if (sender.direction == .Right) {
            print("Swipe Right")
            self.performSegueWithIdentifier("eventsModally", sender: self)
        }
    }
}
+6
source

All Articles