arrayscore-dataswiftuinsset

SwiftUI - Saving ARRAY into NSSet


I'am having trouble with adding an Array [Categories] into my Questions entity relationship

enter image description here

The categories relationship being a "to many" it is an NSSet, so I would like to add my [Categories] array into this NSSet.

I have tried something like this, but nothing gets in.

newQuestion.categories?.addingObjects(from: self.selections)

self.selection being an Array of

Thanks for your help.

Tim


Solution

  • Try the following instead of that line

    if let categories = newQuestion.categories {
        newQuestion.categories = categories.addingObjects(from: self.selections)
    } else {
        newQuestion.categories = Set(self.selections)
    }