Как передать переменную из дочернего в родительский View в SwiftUI?
import SwiftUI
struct ViewParent: View {
@State private var show= true
var body: some View {
VStack {
if show {
Text("Этот текст в родительском View")
}
ViewChild(showC:$show)
}
}
}
struct ViewChild: View {
@Binding var showC: Bool
var body: some View {
VStack {
Button(action:{withAnimation {if showC {showC=false}
else
{showC=true}}}){Text("Скрыть/Показать")}
}
}
}
