Error fetching: Error Domain=NSCocoaErrorDomain Code=134060
"The operation couldn’t be completed. (Cocoa error 134060.)"
UserInfo=0x132eb960 {reason=The fetched object at index 76
has an out of order section name 'å. Objects must be sorted by section name'}
我查了一下,还有其他同名的问题,但是在这种情况下,问题是由于变音字母符号而出现的。
- (NSFetchedResultsController *)fetchedResultsControllerWithPredicate:
(NSPredicate *)aPredicate {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
fetchRequest.entity = [Word MR_entityDescription];
[fetchRequest setFetchBatchSize:20];
[fetchRequest setPredicate:aPredicate];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCompare:)];
fetchRequest.sortDescriptors = @[sortDescriptor];
NSFetchedResultsController *aFetchedResultsController =
[[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:localContext
sectionNameKeyPath:@"name.stringGroupByFirstInitial" cacheName:nil];
aFetchedResultsController.delegate = self;
NSError *anyError = nil;
if (![aFetchedResultsController performFetch:&anyError]) {
NSLog(@"Error fetching: %@", anyError);
}
return aFetchedResultsController;
}
如果我替换localizedCompare:
为,compare:
则没有获取错误,但是某些索引的顺序错误,并且没有显示任何部分。