class DataModel: ObservableObject { @Published var name = "Some Name" @Published var isEnabled = false } struct MyView: View { @StateObject private var model = DataModel() // Create the state object. var body: some View { Text(model.name) // Updates when the data model changes. MySubView() .environmentObject(model) } }
struct TextView: View { @StateObject var viewModel = ViewModel() var body: some View { Button { viewModel.count += 1 } label: { Text("count: \(viewModel.count)") } } }
↑こう書き換えてみましたが、現象には変化無かったです。