[Solved by making in an in between type]
struct ColorType: Identifiable {
var id = UUID()
var color: Color
}
End of edit
I have an array with custom SwiftUI Color
s which reside in the assets folder. Within a View
a Foreach
itterates through these values like this:
let colors: [Color] = [Color("InstrumentColor100"),Color("InstrumentColor100"),Color("InstrumentColor101")]
ForEach( colors, id: \.self) { color in
Rectangle().fill(color)
}
This will serve me the runtime error: ForEach<Array, Color, _ShapeView<Rectangle, Color>>: the ID NamedColor(name: "InstrumentColor100", bundle: nil) occurs multiple times within the collection, this will give undefined results!
I do understant this is due to id: .self not finding unique values to create unique ID's. I found this answer stating to use id: \.keyPath
but I do not have a keyPath rendering 3 aditional errors.
What would be a low overhead way to make these values (apear) unique?
BTW, the code works, but the console overflows wthe the sayd error.