在主视图中调用一个视图环境对象时可以构建成功,但是当我调用第二个视图环境对象时,它会在调用中抛出一个错误额外参数。
struct mainView: View{
@EnvironmentObject var userInterestVM: User_Interests_ViewModel
var body: some View {
FirstEnvironmentObjectView()
FirstEnvironmentObjectView() //<--(error: Extra Argument in call)
// if i call first environment with argument like that
FirstEnvironment(UserInterestsVM: <what I put here>)
// what should I put in the argument)
}
}
struct FirstEnvironmentObjectView: View {
@EnvironmentObject var UserInterestsVM: User_Interests_ViewModel
var body: some View {
Text("check by default values of model.").onTapGesture {
print("fitness \(UserInterestsVM.fitness)")
}
}
struct FirstEnvironmentObjectView_Previews: PreviewProvider {
static var previews: some View {
testing()
.environmentObject(User_Interests_ViewModel())
}
}