0

how do I initialise both, the managedObjectContext and the .environmentObject in the scenedelegate root view ?

I tried all variations of this code - it didn't work:

let contentView = ContentView().environment(\.managedObjectContext, context)

        // Use a UIHostingController as window root view controller.
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: contentView.environmentObject(UserSettings()))
            self.window = window
            window.makeKeyAndVisible()
        }

Thanks for your help!

robsldczk
  • 11
  • 3

1 Answers1

0

This worked fine for me.

let userSettings = UserSettings()

let contentView = ContentView()
        .environment(\.managedObjectContext, context)
        .environmentObject(userSettings)
KevinP
  • 2,562
  • 1
  • 14
  • 27