I'm trying to rewrite this line in Swift 3 Swift 2: let longPress: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "longPressDetected")
Swift 3:
let longPress: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: Selector(("longPressDetected")))
but it seems to be throwing this error
unrecognized selector sent to instance
The function that is's trying to call is this:
func longPressDetected(_ sender: Any){}
答案 0 :(得分:1)
The corresponding selector for
func longPressDetected(_ sender: Any){}
in Swift 3 is
#selector(longPressDetected(_:))
or even simply
#selector(longPressDetected)
Side-note: Since the sender is a distinct type you should specify this:
func longPressDetected(_ sender: UILongPressGestureRecognizer){}
and don't annotate types the compiler can infer.