The code below creates a simple HStack
that ends up looking like this:
The problem is that hitting "increment" increments "Count" but not "Nested". Does anyone know why this is the case and possibly how to fix this? Or do SwiftUI views just fundamentally break when they are nested in a State
variable?
struct ContentView: View {
var body: some View {
VStack {
Text("Count: \(count)")
nested
Button(action: {
self.count += 1
self.nested.count += 1
}) { Text("Increment") }
}
}
@State var count = 0
struct Nested: View {
var body: some View {
Text("Nested: \(count)")
}
@State var count = 0
}
@State var nested = Nested()
}