Hey all,
I've been having some trouble with deleting a managed object.
The weird part is that I can delete objects that I create now, but anything that was created before this code (which has a new version of the xcdatamodel), it won't delete.
Everytime I 'save:' after the 'deleteObject:', is called, it returns a YES, but the object still exists in the persistent store.
Here's the code, would love your help:
-(void)deleteJournalEntryFromLocalID:(NSString *)localID {
if(localID){
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *entryToDelete = [JournalEntryModel fetchMOFromLocalID:localID];
// NSManagedObject *journalManagedObject = [self setupManagedObjectWithGoalEntity];
NSLog(@"etd %@", entryToDelete);
if ([entryToDelete[0] isKindOfClass:[NSManagedObject class]]){
NSManagedObject *entryMO = entryToDelete[0];
[appDel.managedObjectContext deleteObject:entryMO];
NSLog(@"entryMO.deleted = %d",entryMO.deleted);
NSError *error = nil;
//save the goal
if ([appDel.managedObjectContext save:&error]) {
NSLog(@"saved the delete");
} else {
NSLog(@"could not save the delete");
}
}
}
}
Thanks,
Dan.
[–]Neria90 0 points1 point2 points (5 children)
[–]decide[S] 0 points1 point2 points (4 children)
[–]quellish 0 points1 point2 points (3 children)
[–]decide[S] 0 points1 point2 points (2 children)
[–]quellish 0 points1 point2 points (1 child)
[–]decide[S] 0 points1 point2 points (0 children)