3

I have two tables with relations.

enter image description here

At ShopItem class trying to save product:

let productEntity = NSEntityDescription.entityForName("Product", inManagedObjectContext: self.managedObjectContext!)
                    product = Product(entity: productEntity!, insertIntoManagedObjectContext: self.managedObjectContext!)

if let product_title:String = jsonObj["product_title"] as? String {
                        product.setValue(product_title, forKey: "product_title")
                    } else {
                        product.setValue("", forKey: "product_title")
                    }

                    product.setValue(self, forKey: "shopitem")
                    do {
                        try self.managedObjectContext!.save()
                    } catch {
                        fatalError("Failure to save context: \(error)")
                    }

jsonObj - it is a json response from server.

And get an error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet' 
Arti
  • 5,595
  • 11
  • 44
  • 102

1 Answers1

3

I solved problem by adding @objc(Product) to my class.

@objc(Product)
class Product: NSManagedObject {
    ...
}

Can anyone explain what does this mean ?

Arti
  • 5,595
  • 11
  • 44
  • 102