I have two view controllers. I have navigated from one view to another view by press the button to using below code.
 *let secondViewController = self.storyb         
        
All you need is to check with nibName of the viewController and you have your result
this code below will make sure you don't add one viewController again in navigatoinController,
    var VC = YourViewController
    var objVC = (storyboard.instantiateViewController(withIdentifier: "YourViewController"))
    
if navigationController.viewControllers.contains(where: { (VC) -> Bool in
            return objVC.nibName == VC.nibName
        }){
            for (i,controller) in navigationController.viewControllers.enumerated()
            {
                if controller.isKind(of: VC){
                    navigationController.viewControllers.remove(at: i)
                    navigationController.pushViewController(objVC, animated: false)
                }
            }
        }else{navigationController.pushViewController(objVC, animated: false)}
and If you just want to check if the viewController is in NaviagtionController then try this:
var checkForView = navigationController.viewControllers.contains(where: { (VC) -> Bool in
            return objVC.nibName == VC.nibName
        })