[ad_1]
I’ve tried the next (simplified extraction):
struct MyView : View {
var names: [String]
@State non-public var flags = [String : Bool]()
var physique: some View {
ForEach(names, id: .self) { identify in
Toggle(isOn: $flags[name]) { <== ERRORS
...
}
}
.onAppear {
for identify in names {
flags[name] = false
}
}
}
}
This ends in three errors:
Can't convert worth of kind 'Slice<Binding<[String : Bool]>>' to anticipated argument kind 'Binding<Bool>'Can't convert worth of kind 'String' to anticipated argument kind 'Vary<Binding<[String : Bool]>.Index>'Referencing subscript 'subscript(_:)' on 'Binding' requires that '[String : Bool]' conform to 'MutableCollection'
In all probability a foolish query, however why would not $flags[name], which is a dictionary, merely lead to one worth: a Binding<Bool>?
How can this be resolved?
[ad_2]
