-2

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

Dilip Tilonia
  • 63
  • 1
  • 6

1 Answers1

1

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")
    }
}
Siyavash
  • 970
  • 9
  • 23
  • could you plez explain why i need to use this, where in xcode8 there was nothing such as – Dilip Tilonia Aug 30 '17 at 02:30
  • "A Swift class or protocol must be marked with the @objc attribute to be accessible and usable in Objective-C. This attribute tells the compiler that this piece of Swift code can be accessed from Objective-C." because #selector is objective C so you need to make your method accessible with objective C – Siyavash Aug 30 '17 at 02:34
  • i got that but i'm question is this error was not showing in xcode8 – Dilip Tilonia Aug 30 '17 at 02:39