I'm trying to pass one variable from one view to another in SwiftUI. I have a reset button in which I want to set the variable to zero in the other view.
I have tried creating a new struct in view one and accessing that variable in view 2.
// View 1
@State var count = MyNumber.number
// Body of app
Button(action: {self.count = self.count-10}) {
Text("-")
}
Text("\(count)")
struct MyNumber {
static var number = 0
}
// View 2
@State var countit = MyNumber.number
// Body
Button(action: {self.countit = 0}) {
Text("Reset")
}
Text in view one is still showing the number that was computed in View 1