NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 }
    }

2      

Very helpful, thanks!

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.