Reputation: 3114
I am trying to declare a gesture recogniser. When I declare it in the function it works fine but when I declare at the class level so it is available to multiple functions I get the error.
Cannot convert value of type 'NSObject -> () -> ViewController' to expected argument type 'AnyObject?'
I am declaring it like this:
let gestureBack = UIPanGestureRecognizer(target: self, action: Selector("wasDraggedBack:"))
Upvotes: 0
Views: 1432
Reputation: 72410
If you want Gesture
object available to multiple function than declare its instance at class level and initialize the object in viewDidLoad
like this.
var gestureBack: UIPanGestureRecognizer?
override func viewDidLoad() {
super.viewDidLoad()
self.gestureBack = UIPanGestureRecognizer(target: self, action: Selector("wasDraggedBack:"))
}
Upvotes: 4