I generated a CoreData model with some 1-to-many relationships. Now I want to use a ForEach on this relationship which is a NSSet
, then I'm getting the following error:
Generic struct 'ForEach' requires that 'NSSet' conform to 'RandomAccessCollection'
My code looks like this:
struct DetailView: View {
var sample: Sample
var body: some View {
VStack {
ForEach(sample.stepps!, id: \.self) { step in
...
}
}
}
}
How to solve this?
Here is possible approach
ForEach(Array(sample.stepps! as Set), id: \.self) { step in
// step is NSObject type, so you'll need it cast to your model
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With