soleil
soleil

Reputation: 13073

MagicalRecord deleteObject not working

Here is the code:

[[NSManagedObjectContext MR_defaultContext] deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
        NSError *error = nil;
        [[NSManagedObjectContext MR_defaultContext] save:&error];
        [self.collectionView reloadData];

When I delete an object, the collection view reloads and the object is gone. However, the next time I run the app, the object shows up again. What else do I need to do to delete it permanently?

EDIT: I also tried this after deleteObject:

[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];

The object still shows up the next time I run the app.

Upvotes: 2

Views: 1967

Answers (1)

casademora
casademora

Reputation: 69647

Try:

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSManagedObject *obj = [[fetchedResultsController fetchedObjects] objectAtIndex:index];
[obj MR_deleteEntityInContext:context];
[context MR_saveToPersistentStoreAndWait];

Upvotes: 3

Related Questions