how to collect @State variables swiftui code example
Example: how to pass state variable in swiftui
// View1:
struct FirstView: View {
@State var count = 0
var body: some View {
VStack{
Text("\(self.count)")
Button(action:
{self.count = self.count-10})
{
Text("-")
}
SecondView(count: self.$count)
}
}
}
// And View2:
struct SecondView: View {
@Binding var count: Int
var body: some View {
Button(action: {self.count = 0}) {
Text("Reset")
}
}
}