开发者

How do you nullify an attribute in Core Data?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜