Reputation: 23
I am trying to delete an entity in core data.
I use the following code:
//update core data
[context deleteObject:myEntity];
[myEntity deleteInContext:context];
[context save:&error];
So far I know that actually one of the delete lines should do the job, however none of them does. Nothing happens at all. No error message. Nothing happens. context is my NSManagedObjectContext.
Can anyone help me? Thank you!!!!!
Upvotes: 2
Views: 8352
Reputation: 31016
In consideration of your result from logging the context: (null), the fix has to be to use a valid context.
Upvotes: 0
Reputation: 2779
[context deleteObject:myEntity]
is enough to delete an object. [myEntity deleteInContext:context]
is redundant.
If you want the changes to be visible at once, do [context processPendingChanges], otherwise the object will be marked as "to be deleted", but the changes will be processed in the end of the runloop cycle.
Upvotes: 4