我认为是这样的情况,指定为环境对象的类中的@Published 属性会自动更新到我将环境对象传递给的所有子视图,但是下面的代码没有更新,我做错了什么?
class trackerDataStore: ObservableObject {
let healthStore = HKHealthStore()
@Published var isLoadingWorkouts = false
@Published var subscriptionIsActive = false
@Published var trackerWorkoutObject: trackerWorkoutObject?
}
struct detailHeaderCard: View {
@EnvironmentObject var trackerDataStore: TrackerDataStore
var body: some View {
//omitted
}
.sheet(isPresented: $isShowingPlayerAddStatsFormAsModal) {
PlayerAddStatsForm(isShowingPlayerAddStatsFormAsModal: $isShowingPlayerAddStatsFormAsModal)
.environmentObject(trackerDataStore)
}
}
struct PlayerAddStatsForm: View {
@EnvironmentObject var trackerDataStore: TrackerDataStore
//not getting reactively updated here
}