Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core data [NSSet intersectsSet:]: set argument is not an NSSet

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' 
like image 830
Arti Avatar asked Dec 05 '25 03:12

Arti


1 Answers

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

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

Can anyone explain what does this mean ?

like image 151
Arti Avatar answered Dec 07 '25 18:12

Arti



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!