无法将 'NSSet?' 类型的值转换为预期的参数类型 'Range<Int>'(使用 CoreData)



使用CoreData我不知道如何解决这个问题:

错误:Cannot convert value of type 'NSSet?' to expected argument type 'Range<Int>'

private func displayTopics(subject: Subject) -> some View {
NavigationView {
Form {
List {
ForEach(subject.topics) { topic in
NavigationLink(
destination: Text("Destination"),
label: {
Text("Navigate")
})
}
}
}
}

我该怎么办?

ForEach不理解NSSet,您必须在数组中转换它:

if subject.topics != nil {
ForEach(Array(subject.topics! as Set), id: .self) { topic in
NavigationLink(
destination: Text("Destination"),
label: {
Text("Navigate")
})
}
}

相关内容

最新更新