this is a Macos app where the parsclass is setup in a previous view that contains the YardageRowView below. That previous view is responsible for changing the contents of the parsclass. This is working is other views that use a NavigationLink to display the views.
When the parsclass is changed, this view is refreshed, but the previous value is put in the text field on the holeValueTextView.
This is the output of the logs being done
- ** YardageRowView
- ** Before 110
- ** After 110
- ** holeValueTestView 337
- ** Before 222
- ** After 222
- ** holeValueTestView 347
The Before 110 and After 110 are correct...the holeValueTestView 337 is from the previous content of the parsclass and had been displayed already before the parsclass was changed
I cannot comprehend how the value is not being passed into the holeValueTestView correctly
This is a view shown as a .sheet, and if I dismiss it and display it again, everything is fine.
struct YardageRowView: View {
@EnvironmentObject var parsclass: parsClass
var body: some View {
HStack(spacing: 0) {
myLog("YardageRowView ")
Text("Yards").frame(width: holeDimensions().titleColumnWidth)
ForEach(parsclass.pars.indices, id: \.self) { indice in
myLog("Before \(String(parsclass.pars[indice].Yardage))")
// this displays the previous value 337
holeValueTestView(value: String(parsclass.pars[indice].Yardage))
myLog("After \(String(parsclass.pars[indice].Yardage))")
// this displays the current value 110
Text(String(parsclass.pars[indice].Yardage))
.foregroundColor(.red)
}
}
}
struct holeValueTestView: View {
@State var value: String
var body: some View {
//return TextField(value, text: $value)
myLog("holeValueTestView \(value)")
Text(value)
}
}