如何在 scenedelegate 根视图中初始化 managedObjectContext 和 .environmentObject ?
我尝试了此代码的所有变体 - 它不起作用:
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()
}
谢谢你的帮助!