Timo
Timo

Reputation: 87

Cannot convert value of type 'NSSet?' to expected argument type 'Range<Int>' (using CoreData)

Using CoreData I don't know how to solve that problem:

Error: 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")
                    })
                }
            }
        }
    }

What should I do?

Upvotes: 4

Views: 2224

Answers (1)

Asperi
Asperi

Reputation: 258087

ForEach does not understand NSSet, you have to convert it in array:

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

Upvotes: 4

Related Questions