Core Data deleteObject: not working?
core-data, ios, iphone
Solution
Any changes that you make to a `NSManagedObjectContext` are temporary until you save it. Try adding this to the end of your method:
if (![context save:&error]) {
NSLog(@"Couldn't save: %@", error);
}
Problem
I'm using the following code: ``` +(void)deleteObject:(NSManagedObjectID*)oId { NSError *error; DFAppDelegate *temp = [DFAppDelegate new]; NSManagedObjectContext *context = [temp managedObjectContext]; NSManagedObject *obj = [context existingObjectWithID:oId error:&error]; [context deleteObject:obj]; } ``` But it doesn't seem to work accordingly. When I restart my application on iOS simulator I can see the object again in the list. I've tried to print the object with the given object id and it is returning the correct object but still the object is not deleted permanently form my core data model. None of my entity is in relationship with another entity. Can anyone explain me what's going wrong? Thanks. EDIT: I've checked for error, but it shows no error.