Reputation: 3088
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 NSMAnagedObject 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]);
}
Upvotes: 1
Views: 373
Reputation: 5266
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.
Upvotes: 2