First of all, you need a way for the SingleMember
view to communicate to the MainView
and vice versa – a two-way communication. You can achieve this with the @Binding
property wrapper. It can be used like this:
struct SingleMember: View {
@Binding var text: String
var body: some View {
TextField("Amount", text: $text)
}
}
You then need to create a source-of-truth for those three values in the parent MainView
that can also be passed to the child SingleMember
views.
You can either create three separate variables or an array of values depending on whether 3 is a fixed value or not. The binding can be created and passed around like this:
struct MainView: View {
@State private var values: [String] = .init(repeating: "", count: 3)
var body: some View {
VStack {
ForEach(0..<3) { i in
SingleMember(text: $values[i])
}
Button("Print all values") {
print(values)
}
}
}
}