I would like to binding value from a function. But I have the following error :
Cannot convert value of type 'Int' to expected argument type 'Binding<Int>'
Example code :
struct MyFirstView: View {
var body: some View {
MySecondView(index: getIndex())
}
func getIndex() -> Int {
/* Code to get the index.... */
return index
}
}
struct MySecondView: View {
@Binding var index: Int
var body: some View {
Text("Current index : ", index)
}
}
Thanks.
Binding? If the value is not being modified inMySecondViewjust use a standard propertylet index: Int