我有这个fetchedResult方法:
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Cards" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Cards" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __fetchedResultsController;
}
但是当我要求self.fetchedResultsController.fetchedObjects.count
时,它总会给我一件物品,而不是它应该给我的物品。第一项是这个:"<Cards: 0x83e9c50> (entity: Cards; id: 0x83e9c80 <x-coredata:///Cards/t8C371600-7875-468C-A529-C918F0008C384> ; data: {\n cardID = nil;\n favourite = 0;\n imageData = nil;\n})"
但是通过终端检查sqlite我可以看到这个项目不在那里。什么可能是什么?
答案 0 :(得分:0)
很难理解发生了什么。你的代码看起来不错。但是如果你使用缓存机制,这可能是你的奇怪行为。
要进行测试,请尝试在nil
中使用NSFetchedResultsController
而不是缓存,或先删除缓存,然后再执行请求。
+ (void)deleteCacheWithName:(NSString *)name
如果您通过nil
,则会删除所有奖金。
如果你解决了,请告诉我。
P.S。我认为在引擎盖下,现金可以保存,并且可以在不同的应用创业公司之间生活。有谁知道这个?