Let's say I have an array that I am appending first with one element in another view, and then appending with the second element from the third view. How to return to the starting view and deduce two additional views from memory?
struct ContentView: View {
@State var array: [String] = []
var body: some View {
NavigationView{
ScrollView{
ForEach(array, id: \.self) { element in
Text(element)
}
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink("+") {
Details(array: $array)
}
}
}
}
}
}
struct Details: View {
@Binding var array: [String]
var body: some View {
Button(action: { array.append("First Element") }) {
Text("Append First Element")
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink("+") {
}
}
}
}
}
struct MoreDetails: View {
@Binding var array: [String]
@Environment(\.dismiss) var dismiss
var body: some View {
Button(action: { array.append("Second Element") }) {
Text("Append Second Element")
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
NavigationLink("Done") {
ContentView(array: array)
}
.simultaneousGesture(TapGesture().onEnded{
dismiss()
})
}
}
}
}