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
You cannot assign to
testanything from anywhere inside yourContentView, because it is struct and, so,selfis immutable, but you will be able to do something like in the following: