how to pass variable into function swift code example
Example 1: how to pass state variable in swiftui
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)
}
}
}
struct SecondView: View {
@Binding var count: Int
var body: some View {
Button(action: {self.count = 0}) {
Text("Reset")
}
}
}
Example 2: swift function in a variable
var pendingFunction: ((Double, Double) -> Double)