I have checked several related issue like How can I tell whether an `NSManagedObject` has been deleted?, Avoid fetching deleted NSManagedObjects.
But I did using deleteCacheWithName
and deleteObject:
and save
, and have check the object has been deleted too. Every time I remove App from the background. And start it all over, the deleted data NSManagedObject
come back again.
This is how I delete NSManagedObject
.
[NSFetchedResultsController deleteCacheWithName:@"MyLists"];
[_fetchedResultsController.managedObjectContext deleteObject:list];
NSError *error;
if ([_fetchedResultsController.managedObjectContext save:&error]) {
NIDPRINT(@"managedObjectContext Save Error: %@", error.localizedDescription);
}
NIDPRINT(@"Check hasManagedObjectBeenDeleted: %@", [self hasManagedObjectBeenDeleted:list] ? @"YES" : @"NO");
And this is how I initial NSFetchedResultsController
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"MyList"];
fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:@"listID" ascending:YES] ];
NSString *userName = [[ICAccountManager sharedManager] getUsername];
NSString *format = [NSString stringWithFormat:@"username==\"%@\"", userName];
fetchRequest.predicate = [NSPredicate predicateWithFormat:format];
fetchRequest.propertiesToFetch = [NSArray arrayWithObject:@"count"];
fetchRequest.shouldRefreshRefetchedObjects = YES;
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[(id)[[UIApplication sharedApplication] delegate] managedObjectContext] sectionNameKeyPath:nil cacheName:@"lists"];
_fetchedResultsController.delegate = self;
[_fetchedResultsController performSelectorOnMainThread:@selector(performFetch:) withObject:nil waitUntilDone:YES modes:@[ NSRunLoopCommonModes ]];
Is there any way I can check if I miss anything?