我只看到一个空列表,我选择我的语言为法语。下面是一些与此相关的代码。
+ (NSFetchedResultsController *)fetchedResultsControllerForAirportTranslationsInLanguage:(NSString *)theLanguage inContext:(NSManagedObjectContext *)moc_ {
NSLog(@"language is %@",theLanguage);
NSFetchedResultsController *fetchedResultsController = nil;
AirportTranslationFetchRequest *request = [[AirportTranslationFetchRequest alloc] initWithLanguage:theLanguage inManagedObjectContext:moc_];
NSSortDescriptor *sortDescriptorCity = [[NSSortDescriptor alloc] initWithKey:@"city" ascending:YES];
NSSortDescriptor *sortDescriptorName = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptorCity, sortDescriptorName, nil];
[request setSortDescriptors:sortDescriptors];
fetchedResultsController = [[[XXXGMFetchedResultsControllerDoubleByte alloc] initWithFetchRequest:request managedObjectContext:moc_ sectionNameKeyPath:@"firstLetterOfCity" cacheName:nil] autorelease];
[sortDescriptorCity release];
[sortDescriptorName release];
[sortDescriptors release];
[request release];
NSError *error = nil;
if (![fetchedResultsController performFetch:&error]) {
LogError(@"An error occured while performing fetch request: %@", error);
}
return fetchedResultsController;
}
它适用于所有其他语言,如中文、日文、韩文。
- (NSString *)firstLetterOfCity {
[self willAccessValueForKey:@"firstLetterOfCity"];
NSString *aString = [[self valueForKey:@"city"] uppercaseString];
NSLog(@"ABCD %@",aString);
NSString *stringToReturn = nil;
if (aString.length < 1) {
stringToReturn = @"?";
}
else {
stringToReturn = [aString substringToIndex:1];
}
[self didAccessValueForKey:@"firstLetterOfCity"];
return stringToReturn;
}
根据下面的日志,我猜 Core Data 无法处理法语中的特殊字符。
2015-03-27 11:51:17.543 XXX[1503:60b] 义乌市
2015-03-27 11:51:17.543 XXX[1503:60b] 日惹市
2015-03-27 11:51:17.544 XXX[1503:60b] 米子市
2015-03-27 11:51:17.544 XXX[1503:60b] 南萨哈林斯克市
2015-03-27 11:51:17.545 XXX[1503:60b] 城市扎达尔
2015-03-27 11:51:17.545 XXX[1503:60b] 萨格勒布市
2015-03-27 11:51:17.546 XXX[1503:60b] 桑给巴尔市
2015-03-27 11:51:17.547 XXX[1503:60b] 城市张家界
2015-03-27 11:51:17.547 XXX[1503:60b] 郑州
2015-03-27 11:51:17.548 XXX[1503:60b] 珠海市
2015-03-27 11:51:17.548 XXX[1503:60b] 苏黎世市
2015-03-27 11:51:17.549 XXX[1503:60b] CITY LAŞI
2015-03-27 11:51:17.549 XXX[1503:60b] CoreData: error: (XXXGMFetchedResultsControllerDoubleByte) 在索引 1025 处获取的对象有一个乱序部分名称“Z”。对象必须按部分名称排序' 2015-03-27 11:51:17.553 XXX[1503:60b] +[XXXGMAirportTranslation fetchedResultsControllerForAirportTranslationsInLanguage:inContext:][Line 69] [ERROR] 执行获取请求时发生错误:错误域 = NSCocoaErrorDomain Code=134060 “操作无法完成。(Cocoa 错误 134060。)” UserInfo=0x168429f0 {reason=在索引 1025 处获取的对象有一个乱序部分名称 'Z。对象必须按部分名称排序'}
通过nil
而不是firstLetterOfCity
给我列表,但它没有排序。