I am trying to dismiss a viewController to rootViewController while signOut. But the problem is that the viewController is not getting dismissed, It still remains in the same page itself. Below I have mentioned the code that I have used.
    let AppDel = UIApplication.shared.delegate as! AppDelegate
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let login = mainStoryboard.instantiateViewController(withIdentifier: "login")
    let nav = UINavigationController(rootViewController: login)
    AppDel.window!.rootViewController = nav
    AppDel.window?.rootViewController?.dismiss(animated: true, completion: nil)
    (AppDel.window?.rootViewController as? UINavigationController)?.popToRootViewController(animated: true)
    login.navigationController?.setNavigationBarHidden(true, animated: false)
Thanks in advance.
 
     
     
     
     
    