【发布时间】:2020-07-09 01:26:18
【问题描述】:
我生成了一个包含一对多关系的 CoreData 模型。现在我想在 NSSet 这个关系上使用 ForEach,然后我收到以下错误:
Generic struct 'ForEach' requires that 'NSSet' conform to 'RandomAccessCollection'
我的代码如下所示:
struct DetailView: View {
var sample: Sample
var body: some View {
VStack {
ForEach(sample.stepps!, id: \.self) { step in
...
}
}
}
}
如何解决?
【问题讨论】:
-
您确定要
ForEach而不是forEach? -
forEach 在 SwiftUI 中不起作用