My app architecture is :
RootNavigationController
-(rootVC)> HomeVC
-(pushed)> SecondVC
-(presented)> SecondNavigationController
-(rootVC)> ThirdVC
-(pushed)> FourthVC.
Now there is an option of returning to HomeVC on FourthVC.
What I have tried:
1)
APPDELEGATE.window?.rootViewController = UIStoryboard.HomeNavigationViewController()
Problem : This way all VCs added on RootNavigationController are not deinitilized and memory leaked.
2)
self.dismiss(animated: true, completion: nil)
(self.navigationController?.presentingViewController as? UINavigationController)?.viewControllers.removeAll()
APPDELEGATE.window?.rootViewController = UIStoryboard.HomeNavigationViewController()
This way its working fine but what I need to know is there any better way of doing it.