is it possible to set a variable in SwiftUI e.g. in a ForEach like this:
struct ContentView: View {
var test: Int
var body: some View {
List {
ForEach(1...5, id: \.self) {
Text("\($0)…")
test = $0 // how to realise this?
}
}
}
}
I can not bring this to live, I'm getting an error like:
Unable to infer complex closure return type; add explicit type to disambiguate
What you can do is using a @State var definition and apply the value from a task inside your foreach. Example:
}