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

Hacking With iOS: UIKit Edition >> Project 7 Errata

Forums > Books

Since the chapter was written, I think there has been an update to the code generated by XCode for new projects. Therefore, example of manually adding a second tab to the tabview needs to move from AppDelegate to SceneDelegate. The code will now be here:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        let tabBarController = window?.rootViewController as? UITabBarController
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "NavController")
        vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
        tabBarController?.viewControllers?.append(vc)
        guard let _ = (scene as? UIWindowScene) else { return }
    }

4      

Very helpful, thanks!

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.