4

使用 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")
                    })
                }
            }
        }
    }

我应该怎么办?

4

1 回答 1

3

ForEach 不明白NSSet,你必须把它转换成数组:

if subject.topics != nil {
    ForEach(Array(subject.topics! as Set), id: \.self) { topic in
        NavigationLink(
            destination: Text("Destination"),
            label: {
                Text("Navigate")
        })
    }
}
于 2020-11-23T18:21:49.327 回答