Search code examples
swiftuinavigationcontrolleruitabbarcontroller

iOS - How to remove UINavigationController from AppDelegate?


I have to remove UINavigationController from my app to add UITabBarController and keep my if statement works as is.

My Code :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if UserDefaults.standard.value(forKey: "URL") == nil
    {
        let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        let navController = UINavigationController(rootViewController: viewController)
        self.window?.rootViewController = navController
        self.window?.makeKeyAndVisible()

    }else{

        let viewController = storyboard.instantiateViewController(withIdentifier: "ChannelsViewController") as! ChannelsViewController
        let navController = UINavigationController(rootViewController: viewController)
        self.window?.rootViewController = navController
        self.window?.makeKeyAndVisible()
    }

    return true
}

Solution

  •     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    
        if UserDefaults .standard .value(forKey: "URL") == nil
        {
            let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
            self.window?.rootViewController = viewController
            self.window?.makeKeyAndVisible()
    
        }else{
    
            let viewController = storyboard.instantiateViewController(withIdentifier: "ChannelsViewController") as! ChannelsViewController
            self.window?.rootViewController = viewController
            self.window?.makeKeyAndVisible()
        }
    
    
        return true
    }