假设我有一个 Core Data NSManagedObject,它有一个存储图像的属性。如果我想删除图像而不是 NSMAnagedObject,我该怎么做?
我现在正在使用。这似乎有效,但我遇到与此代码相关的间歇性崩溃,所以我想确定一下。
-(void)deletePhoto{
note.thumbnail = nil; //This is a thumbnail image
[context deleteObject:note.image]; //This is an image related to the object via a to-one relationship
NSError *error;
if (![context save:&error])
NSLog(@"Error saving: %@", [error localizedDescription]);
}
最佳答案
我认为您应该让 Core Data 处理它。您应该将关系设置为“级联删除”,然后在代码中将其设置为 nil。
note.image = nil; // Rather than delete object.
关于ios - 如何使 Core Data 中的属性无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5225278/