How do you make child views' state accessible by the parent view?

Say in a SwiftUI board game, the board view is composed of several cell views and each cell view encapsulates whether it was pressed. What would be a good approach to making the parent board view know about that @State?

Replies

Did you consider environment properties ?

You can also have a

@State var vParent in parent and

@Binding var vChild in the child.


You call the childView with

ChildView(vChild: self.$vParent)


When you modify vChild in child, that will propage to vParent in Parent