TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Project 7, I've work along with the code but duplicate view controller is not created in tabbar controller

Forums > 100 Days of Swift

I had writted code in appdelegate to add duplicate viewcontroller via code to tabcontroller, but I did not find another viewcontroller added to tabbarcontroller `func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    if let tabBarController = window?.rootViewController as? UITabBarController {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(identifier: "NavController")
        vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
        tabBarController.viewControllers?.append(vc)
    }

    return true
}

4      

There is an outdated code in the Project 7 of the book Hacking with iOS / 100 Days of Swift

The Xcode 11 project template add a new SceneDelegate.swift file in the project, and the SceneDelegate class manage the iOS app’s UI life cycle.

And in Xcode 11, the template remove the window member variable ( UIKit.UIWindow type ) from AppDelegate class, it add the window member variable to the SceneDelegate class.

So your code must be placed in below SceneDelegate class’s function func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)

Remove the "return true" part

18      

Thank you so much, you are my timesaver.

6      

Life savers!

4      

This helped me a lot! Thanks :)

4      

Thank you, i try this like 4 ours and found this, the best answer i find and it worked

3      

Thank you !

Was stuck here for hours

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.