First Case:When you want to select other tab index
guard let VCS = self.navigationController?.viewControllers else {return }
for controller in VCS {
if controller.isKind(of: TabBarController.self) {
let tabVC = controller as! TabBarController
tabVC.selectedIndex = index . (Select any index for tab)
self.navigationController?.popToRootViewController(animated: true)
}
}
Second Case: When you want to access to RootViewController variables
guard let VCS = self.navigationController?.viewControllers else {return }
for controller in VCS {
if controller.isKind(of: TabBarController.self) {
let tabVC = controller as! TabBarController
// tabVC.selectedIndex = 0 . //no need of this line if you want to access same tab where you have started your navigation
let VCs = tabVC.selectedViewController as! MyViewController
VCs.variableName = true . //access your variable
self.navigationController?.popToRootViewController(animated: true)
}
}