Your Button, defined inside ContentView, is only changing the content of the property within the ContentView. You've passed a copy of that to ChildView, so it has a separate value, stored elsewhere in memory. Thus changing ContentView.msg won't alter the value of ChildView.msg.I suspect that if your ChildView's msg property were not an @State value, then it would be recreated. The way SwiftUI works in regard to state is this:Cleans the 'touched' state on all @State variables.Invokes body on a view.Looks at the 'touched' state on the @State variables.If a state property was accessed, it's marked, so that when that state is modified, it triggers another body call.In your ContentView, you're accessing your local @State property, so changes to that property now trigger a redraw. In the ChildView, you're accessing a different @State property. Now, when ContentView.body is invoked a second time, it generates a view containing a new ChildView with a new value (as expected). Then SwiftUI goes to use
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: