GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course.

Save your spot

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.