magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.79k stars 1.79k forks source link

NSFetchedResultsController and Deleting : Won't Persist #195

Closed wm-j-ray closed 11 years ago

wm-j-ray commented 12 years ago

I must be doing something wrong because I can't get core data to update although the tableview is working properly. Here is the relevant code:

if (editingStyle == UITableViewCellEditingStyleDelete) {

    [self setEditing: YES animated:YES];
    [self.tableView beginUpdates]; // Avoid  NSInternalInconsistencyException

    Tags *tagToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSLog(@"Deleting (%@)", tagToDelete.tagName);

    // "Try" to persist changes to CoreData -- This fails
    [tagToDelete MR_deleteInContext:[NSManagedObjectContext MR_defaultContext]];
    [[NSManagedObjectContext MR_defaultContext] MR_save];        

    // Delete the (now empty) row on the table
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

I get a (MagicalSaves MR_saveWithErrorCallback -> Saving <NSManagedObjectContext

Can anybody give me a pointer as to what I'm doing wrong>

Thanx in Advance

blackgold9 commented 12 years ago

Interesting. The code seems to show that calling MR_save should also save the background io queue. Are you running a current version of Magical Record? If this is still happening, let me know. A sample project would also do wonders in helping iron this out.

wm-j-ray commented 12 years ago

Got it to work by:
[[NSManagedObjectContext MR_defaultContext] MR_saveNestedContexts];

And I believe I'm using the latest version. Noob Question: How can I be sure?

tonyarnold commented 11 years ago

Hi @wm-j-ray — that’s a good point re: checking the version you’re using. I’ll have a look at adding some kind of version identifier to a future release.