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      

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.