Epic Gamer_1 Epic Gamer_1 - 6 months ago 52
Swift Question

Swift 2.2 - Value of type ViewController has no member action

I have been getting the error "Value of type 'ViewController' has no member 'action'"

(action being the function)

Here is the code I am using for the function and Gesture Recogniser

let uilpgr = UILongPressGestureRecognizer(target: self, action: #selector(self.action))

uilpgr.minimumPressDuration = 2


func action(gestureRecogniser: UIGestureRecognizer) {

print("Gesture Recognised")


let uilpgr = UILongPressGestureRecognizer(target: self, action: #selector(self.action))

This is where the error occurs at self.action

What am I doing wrong and how do I fix it?


Your method action is declared locally within the same method that is creating the gesture recognizer.

To resolve this move your action method outside of the method it is currently in. So that is is its own method of the class ViewController and not inside any other functions.