ios - 如何使 Core Data 中的属性无效?

标签 ios core-data

假设我有一个 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]);

} enter image description here

最佳答案

我认为您应该让 Core Data 处理它。您应该将关系设置为“级联删除”,然后在代码中将其设置为 nil。

note.image = nil; // Rather than delete object.

关于ios - 如何使 Core Data 中的属性无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5225278/

相关文章:

objective-c - wsdl2objc: 'libxml/tree.h' 找不到文件

ios - 在框架目标 : file not found 中包含一个 pod

ios - 物理 IOS/Android 设备上的 Firebase Firestore 模拟器

iphone - 通过 NSValueTransformer 将字符串转换为核心数据

ios - 对核心数据进行排序 nsarray numeric

ios - Swift 中的 EXC_BAD_ACCESS 错误代码

iphone - UIManagedDocuments 什么时候关闭?

objective-c - 如何使用 UISilder 在 SubView 中添加和删除 UIButtons?

ios - 核心数据自定义可转换对象类数组

android - 统一游戏 : Best practices for setting up a config file