Search code examples
iosapplication-lifecycle

How to : Debug UIWindows were created prior to initial application activation


My console posted this error today, [ApplicationLifecycle] UIWindows were created prior to initial application activation. This may result in incorrect visual appearance.

This has caused Application UI to not behave properly. I have never seen this before and need some insight on where to start debugging.

macOS: Catalina 10.15
XCode version: Version 11.1 

Solution

  • I think that apps main UIWindow should be lazily initiated. Try with this:

    import UIKit
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
        lazy var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            window?.rootViewController = RootViewController() // root view controller
            window?.makeKeyAndVisible()
    
            return true
        }
    }