Reputation: 2178
Since SwiftUI 2.0 does not have an AppDelegate and SceneDelegate anymore, where should EnvironmentObjects be set?
This how it was done previously, where do i have to add them now?
window.rootViewController = UIHostingController(rootView: ContentView()
.environmentObject(settings))
Upvotes: 0
Views: 1143
Reputation: 54486
Try the following:
@main
struct TestApp: App {
@StateObject var settings: Settings = ... // init here
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(settings)
}
}
}
Upvotes: 5