我已经检查了几个相关问题,例如如何判断 `NSManagedObject` 是否已被删除?,避免获取已删除的 NSManagedObjects。
但是我确实使用了deleteCacheWithName
and deleteObject:
,save
并且检查了该对象也已被删除。每次我从后台删除应用程序时。重新开始,删除的数据NSManagedObject
又回来了。
这就是我删除的方式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");
这就是我最初的方式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 ]];
有什么办法可以检查我是否错过了什么?