Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 11 beta: AppDelegate file doesn't have window global variable

I am facing an issue in Xcode 11 beta.

The problem is that I am not getting default window variable declared in AppDelegate file.

Is anybody facing this same issue?

like image 763
Rashesh Bosamiya Avatar asked Jun 15 '19 14:06

Rashesh Bosamiya


2 Answers

In Xcode 11 this is now done in SceneDelegate

EDIT: if you’re still supporting iOS 12 or prior (or want to support 13 plus prior)

Add the UIWindowSceneDelegate to ApplicationDelegate

Add : var window:UIWindow?

Then proceed as you would to setting up in didFinishLaunching

like image 177
Michael Garcia Avatar answered Sep 19 '22 22:09

Michael Garcia


The default var window: UIWindow? Is now moved in SceneDelegate.swift. To set a rootViewController in Xcode 11 you can work within SceneDelegate.swift file, In the scene delegate, you must create the window instance and the root view controller like below:

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

        // set or create your viewController here
        let yourViewController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "yourViewController") as! YourViewController
        // set the rootViewController here using window instance
        self.window?.rootViewController = yourViewController
    }

Also this answer is helpful : Why is manually setup root view controller showing black screen?

Hope it will help you!

like image 34
Emdad Avatar answered Sep 19 '22 22:09

Emdad