所以现在我的 ContentView 看起来像这样:
struct ContentView: View {
@ObservedObject var appState: AppState
@ObservedObject var lManager: LManager
@ObservedObject var functionMaster: functions
@ObservedObject var sManager: SManager
init() {
let appStateStarter = AppState()
appState = appStateStarter
let sManagerStarter = SManager(appState: appStateStarter)
let functionMasterStarter = functions(appState: appStateStarter)
let lManagerStarter = LManager(appState: appStateStarter, functionMaster: functionMasterStarter, sManager: sManagerStarter)
sManager = sManagerStarter
lManager = lManagerStarter
functionMaster = functionMasterStarter
}
}
我的应用程序文件如下所示:
@main
struct Test_1App: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
//here I need to have access to the functionMaster I defined in ContentView, and by extension the AppState inside of it. How can I do that?
}
}
}
}
我想我必须为 ContentView 重新定义我的 init() 但老实说,我非常不确定如何正确地构造它,以便正确保留所有依赖项。任何帮助将非常感激!