Tim
Tim

Reputation: 129

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

Upvotes: 1

Views: 905

Answers (1)

Asperi
Asperi

Reputation: 258441

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

Upvotes: 3

Related Questions