I have a view (OrderView) which leads to another view via navigationLink. In this new view (StarterView) a variable “total” is updated. This works as I have added a print statement to see that it is updated. When I leave this view back to OrderView, the variable Total which is in a Text(totalViewModel.total) is still at 0. Does anyone know why this won’t update?
Thanks
class TotalViewModel: ObservableObject {
@Published var total: Float = 0
}
struct OrderView: View {
@ObservedObject var totalViewModel: TotalViewModel
var body: some View {
Text("£(totalViewModel.total)")
}```
New contributor
Benjamin Young is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.