Change Initial View Controller in AppDelegate

I'm attempting to create a tutorial like view for my app on the first instance it is loaded up. I'm trying to change the initial view controller through that app delegate from different forums that I've found. I'm not getting any errors when running it, but it doesn't change the Initial VC to the one I want. Anything I am doing wrong?

This block is from my AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {     
    // Override point for customization after application launch.
    GMSServices.provideAPIKey("API Key")
    GMSPlacesClient.provideAPIKey("API Key")
     
     
    let defaults = UserDefaults.standard
//checking to see if app has run before
    if defaults.object(forKey: "isFirstTime") == nil {
      defaults.set("No", forKey:"isFirstTime")
       
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 

      guard let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController else{
        fatalError("Unable to instantiate an ViewController from the sotryboard")
      }
//setting new vc
      self.window?.rootViewController = viewController      
    }
Answered by Frameworks Engineer in 691032022

Why not just present your "first run" view controller as a modal presentation instead? Then you don't need to disrupt the rest of your application by changing the rootViewController at runtime.

Add a print to see what happens.

I would also test defaults:

    if defaults.object(forKey: "isFirstTime") == nil || defaults.object(forKey: "isFirstTime") != "No" {
      defaults.set("No", forKey:"isFirstTime")
      print("isFirstTime")
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
Accepted Answer

Why not just present your "first run" view controller as a modal presentation instead? Then you don't need to disrupt the rest of your application by changing the rootViewController at runtime.

Change Initial View Controller in AppDelegate
 
 
Q