开发者

How do you nullify an attribute in Core Data?

开发者 https://www.devze.com 2023-02-15 14:44 出处:网络
Say I have a Core Data NSManagedObject that has an attribute which stores a image. If I want to delete the image but not the NSMAna开发者_开发问答gedObject how do I do it?

Say I have a Core Data NSManagedObject that has an attribute which stores a image. If I want to delete the image but not the NSMAna开发者_开发问答gedObject how do I do it?

Right now I'm using. This seems to be working but I am getting intermittent crashes related to this code so I'd like to be sure.

-(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]);

}

How do you nullify an attribute in Core Data?


I think you should let Core Data handle that. You should set the relationship to "Cascade Delete" and then set it to nil in code.

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

精彩评论

暂无评论...
验证码 换一张
取 消