#selector in gesture Recognizer in xcode9

324 Views Asked by At

Hii everyone i'm just shifting from xcode8 to xcode9 and when i tryed to use gesture recognizer they xcode9 is showing some error

argument of #selector refers to instate method swipe(gesture) that is not > expose to obj c and here my code

 override func viewDidLoad() {
    super.viewDidLoad()

    let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swipe(gestuer:)))
    swipeLeft.direction = .left
        self.view.addGestureRecognizer(swipeLeft)
}

func swipe(gestuer: UISwipeGestureRecognizer) {
    if gestuer.direction == .left {
        print("this is left swipe")
    }
}

so is it xcode problem of something else

1

There are 1 best solutions below

3
On

You need to use the @objc attribute on swipe(gestuer:) to use it with #selector.

@objc func swipe(gestuer: UISwipeGestureRecognizer) {
    if gestuer.direction == .left {
        print("this is left swipe")
    }
}