Missing 'window' variable in AppDelegate - CoreData

If you’re following along the Setting Up a Core Data Stack tutorial for Swift in the apple website, and you got stuck on the rootVC = window?.rootViewController part, then you’re not alone.

Since iOS 13 (Xcode 11), the life cycle of UIKit introduces UISceneDelegate, read more here.

Thus, you have to change use the following code instead of in the tutorial.

AppDelegate.swift

class AppDelegate: UIResponder, UIApplicationDelegate {

    ...

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {        
        // Just leave it as it, don't change anything
    }

    ...
}

SceneDelegate.swift

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

		...

    rootVC.container = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer
    
		...

}

It sure confused the hell out of me when I started developing an iOS app and following the tutorial.