1

Here's my code of my scene delegate method:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    // Use a UIHostingController as window root view controller
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)

    // Override point for customization after application launch.
    let context = AppDelegate.shared.persistentContainer.viewContext
    context.automaticallyMergesChangesFromParent = true

    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}
Epaga
  • 38,231
  • 58
  • 157
  • 245

1 Answers1

4

This was the original default. Since beta 3, windows need to be initialised like this:

    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView(coordinator:coord, model:store))
        self.window = window
        window.makeKeyAndVisible()
    }
Epaga
  • 38,231
  • 58
  • 157
  • 245