Argument of '#selector' compiler error


I couldn’t get the provided code sample to work without a compiler error when instantiating the doubleTapRecognizer. The use of “#selector” for the action parameter caused an error with Xcode 9.2:

“Argument of ‘#selector’ refers to instance method ‘tap’ that is not exposed to Objective-C”

I won’t duplicate the code, because it matches the printed one.

The “fix” was to expose the method doubleTap(_:slight_smile: to objective-C.

I’m not certain what this means, but it required adding “@objc” to the function declaration:

 @objc func doubleTap(_ gestureRecognizer: UIGestureRecognizer) {
    print ("Recognized a double tap")


This is happening in Swift 4 to improve performance :

Hope this helps.


Thank you so much. I am but only grasshopper in your shadow.