SwiftUI - Saving ARRAY into NSSet

699 Views Asked by At

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

1

There are 1 best solutions below

2
Asperi On BEST ANSWER

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)
}