BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

SOLVED: Is the code in Finishing touches: didFinishLaunchingWithOptions (Day 34, Task 2) out of date?

Forums > 100 Days of Swift

The tutorial asks you to add some code to the didFinishLaunchingWithOptions function in AppDelegate.swift. Unfortunately the code doesn't work as there is no window variable.

if let tabBarController = window?.rootViewController as? UITabBarController { //error: Cannot find 'window' in scope

Is it as simple as declaring var window: UIWindow? as a member variable to the AppDelegate class?

3      

Adding the member variable to AppDelegate does not work, although it does compile. No new tab is displayed in the UI.

3      

Hi there! Yes, structure has been changed since then. Now it is in SceneDelegate.swift

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

  var window: UIWindow?

  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

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

    // This creates second tab bar item
//    if let tabBarController2 = window?.rootViewController as? UITabBarController {
//      let storyboard = UIStoryboard(name: "Main", bundle: nil)
//      let vc = storyboard.instantiateViewController(withIdentifier: "NavController")
//      vc.tabBarItem = UITabBarItem(tabBarSystemItem: .mostViewed, tag: 2)
//      tabBarController2.viewControllers?.append(vc)
//    }

    guard let _ = (scene as? UIWindowScene) else { return }
  }
 }

3      

Thanks for clearing that up. Can the tutorial be updated for future students?

3      

Well this is good question for Paul :) But since all attention now on SwiftUI framework, I wouldn't be so sure that it is going to be updated soon. But nevertheless his course is not so really oudated as others. There are some other places that unfortunately will make your brain hurt :) But nevertheless solvable.

3      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.