If are you using SceneDelegate.swift file in your project then try this way.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
// Instantiate UIWindow with scene
let window = UIWindow(windowScene: scene)
// Assign window to SceneDelegate window property
self.window = window
// Set initial view controller from Your storyboard as root view controller of UIWindow
self.window?.rootViewController = UIStoryboard(name: "Your StoryBoard Name", bundle: nil).instantiateInitialViewController()
// Present window to screen
self.window?.makeKeyAndVisible()
}
if you are not using ScanDelegate.swift and go with AppDelegate.swift then try this way.
Without InitalViewController :
func logOut {
let storyboard = UIStoryboard(name: "Your StoryBoard", bundle: nil)
if let navigationController = storyboard.instantiateInitialViewController() as? UINavigationController,
let loginvc = storyboard.instantiateViewController(withIdentifier: "Your Selected ViewController") as? YourSelectedViewController {
navigationController.viewControllers = [loginvc]
AppDelegate.getAppDelegate().window?.rootViewController = navigationController
}
}
With InitalViewController :
func logOut() {
let storyboard = UIStoryboard(name: "Your StoryBoard", bundle: nil)
let navigationController = storyboard.instantiateInitialViewController()
AppDelegate.getAppDelegate().window?.rootViewController = navigationController
}
Extension :
extension AppDelegate {
class func getAppDelegate() -> AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
}