What's wrong with this code? Swipe Gesture not working

This is my ViewController1

Code Block
class ViewController1: UIViewController {
fileprivate lazy var gestureManager: GestureManager = {
return GestureManager(vc: self)
}()
override func viewDidLoad() {
super.viewDidLoad()
}
}


And this is my GestureManager class:

Code Block class GestureManager {
  var appDelegate = UIApplication.shared.delegate as! AppDelegate
  var vc: UIViewController?
   
  init(vc: UIViewController) {
    print("init controller")
    self.vc = vc
     
    let swipeRight = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeRight.direction = .right
    let swipeLeft = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeLeft.direction = .left
    let swipeUp = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeUp.direction = .up
    let swipeDown = UISwipeGestureRecognizer(target: vc, action: #selector(respondToSwipeGesture(_:)))
    swipeDown.direction = .down
     
    vc.view.addGestureRecognizer(swipeRight)
    vc.view.addGestureRecognizer(swipeLeft)
    vc.view.addGestureRecognizer(swipeUp)
    vc.view.addGestureRecognizer(swipeDown)
  }
   
  @objc func respondToSwipeGesture(_ gesture : UIGestureRecognizer) {
    print("this got fired")
    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
      }
    }
  }
}


It won't throw any error or warnings, it just does not work.

it just does not work.

You should better clarify what you mean by does not work.
You mean any print statements in respondToSwipeGesture(_:) does not output anything?

The worst thing in your code is that you are using lazy for the property gestureManager but you are not using gestureManager anywhere in your code.
Try something like this:
Code Block
class ViewController: UIViewController {
fileprivate lazy var gestureManager: GestureManager = {
return GestureManager(vc: self)
}()
override func viewDidLoad() {
super.viewDidLoad()
print(gestureManager) //<-
}
}


But I would use non-lazy in this case:
Code Block
class ViewController1: UIViewController {
fileprivate var gestureManager: GestureManager!
override func viewDidLoad() {
super.viewDidLoad()
gestureManager = GestureManager(vc: self)
}
}



With this change, you would find something happens, but it may not be what you want.
As I wrote in another thread of yours, your GestureManager has some flaws and you have not fixed them all.

Did you read my answer in the other thread. It is not useful to open several threads on the same topic.

Could you please review the answers in all your threads on this topic and close those that can be closed on a correct answer ?
What's wrong with this code? Swipe Gesture not working
 
 
Q