我有两个关系表。
在尝试保存产品的 ShopItem 类中:
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
- 这是来自服务器的 json 响应。
并得到一个错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSSet intersectsSet:]: set argument is not an NSSet'
最佳答案
我通过将 @objc(Product)
添加到我的类中解决了问题。
@objc(Product)
class Product: NSManagedObject {
...
}
谁能解释一下这是什么意思?
关于swift - 核心数据 [NSSet intersectsSet :]: set argument is not an NSSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33037346/