UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 7: White House Petitions - Use of unresolved identifier ‘window’ in didFinishLaunchingWithOptions

Forums > 100 Days of Swift

am on project 7 on HWS and am getting this error.. followed everything like in tutorial. checked online for solutions. still couldnt get around it.

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

3      

Since Xcode 11 the new template for AppDelegate is changed. Assuming the code above goes in AppDelegate you can try adding this property to the class:

var window: UIWindow?

4      

thanks it worked. i tried replacing window with UIwindow and got error. didnt thought about creating a variable.

found another long solution on reddit havent tried it yet.

this solved that error. and now i can build. my VM crashed. will update final results when am done fully with project.

thanks.

3      

it solved the error that prevented it from building but it didnt add the scond tab bar. gotta try the reddit solution.

3      

Put it in scene delegate.

4      

@K-Aje108

Thanks. Took me a minut to find the right place. I thought it might be there, but didn't really go for it until I saw your message. Got it working

3      

For anyone else wondering about this. I was pouring over my code to see where I messed it up and after I copied this block out of AppDelegate and put it in SceneDelegate:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
       <code goes here>
        guard let _ = (scene as? UIWindowScene) else { return }
    }

That fixed it up PERFECTLY.

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.