I have the following GestureManager class that I want to use to clean up the ViewController where the GestureRecognizer functionality is going to be happening.
class GestureManager {
var vc: UIViewController?
But I would get the following errors in the above variables (rightSwipe, leftSwipe)
Why is this happening? I'm expecting to pass the ViewController to be used in the "target" attribute, but why self cannot be found in scope? Isn't SELF supposed to be pointing to GestureManager class?
This is probably a basic question, but I'm still on they of learning the basics of swift, classes, the different methods etc.
Thanks in advance!
class GestureManager {
var vc: UIViewController?
Code Block @objc func respondToSwipeGesture(_ gesture : UIGestureRecognizer) { if let swipeGesture = gesture as? UISwipeGestureRecognizer { switch swipeGesture.direction { case .right: print("swiped right!") case .left: print("Swiped left") case .up: print("Swiped up") case .down: print("Swiped down") default: return } } } let rightSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) rightSwipe.direction = .right let leftSwipe = UISwipeGestureRecognizer(target: self.vc, action: #selector(respondToSwipeGesture(_:))) leftSwipe.direction = .left
}But I would get the following errors in the above variables (rightSwipe, leftSwipe)
Code Block Cannot find "self" in scope
Code Block Consecutive declarations on a line must be separated by ";"
Why is this happening? I'm expecting to pass the ViewController to be used in the "target" attribute, but why self cannot be found in scope? Isn't SELF supposed to be pointing to GestureManager class?
This is probably a basic question, but I'm still on they of learning the basics of swift, classes, the different methods etc.
Thanks in advance!