Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 591
Timo Avatar asked Oct 19 '25 03:10

Timo


1 Answers

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")
        })
    }
}
like image 104
Asperi Avatar answered Oct 22 '25 04:10

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!