A bad case of SwiftUI magic not working for me, and I am loosing my sanity here. Why is the text not updating its value here? Why is the body not reevaluated after each increment() call?
class ReadingStateVM: ObservableObject {
@Published var value = 0
func increment() {
value = value + 1
print("value \(value)")
}
}
struct ReadingStateView: View {
var viewModel = ReadingStateVM()
var body: some View {
Text("State \(viewModel.value)")
.onTapGesture {
self.viewModel.increment()
}
}
}