struct ContentView {
@ObservedObject var annotationsVM = AnnotationsVM()
//I'd like to pass in the ViewModel() declared below into annotationsVM like AnnotationsVM(VModel: Vmodel)
@ObservedObjects var VModel = ViewModel()
var body: some View {
//All the SwiftUI view setup is in here
}
}
class AnnotationsVM: ObservableObject {
@ObservedObject var VModel = ViewModel()
//I'd like to pass in the VModel in content view like: @ObservedObject var VModel: VModel
}
显然,我不能像我想要的那样在 ContentView 创建时直接传递 VModel,因为 VModel 对象尚未创建,因此无法访问......
回顾:我想将在 ContentView 中声明的 VModel 实例传入 annotationsVM 实例(也在 ContentView 中声明)