iPhone CoreData:使用umlauts排序

iPhone CoreData:使用umlauts排序,iphone,sorting,core-data,fetch,diacritics,Iphone,Sorting,Core Data,Fetch,Diacritics,我有一个从sqlite数据库获取数据(国家列表)的应用程序。 这些国家使用德语,并包含umlauts,例如Österreich。我想将这些国家按名称排序,并期望Österreich与其他国家的“O”相近,但结果却在最后 此代码用于获取已排序的国家/地区: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity: [NSEntityDescription entityForNa

我有一个从sqlite数据库获取数据(国家列表)的应用程序。 这些国家使用德语,并包含umlauts,例如Österreich。我想将这些国家按名称排序,并期望Österreich与其他国家的“O”相近,但结果却在最后

此代码用于获取已排序的国家/地区:

 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

 [fetchRequest setEntity: [NSEntityDescription entityForName: @"Continent" inManagedObjectContext: moc]];
    [fetchRequest setSortDescriptors: [NSArray arrayWithObject: [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES] autorelease]]];

 NSError *error = nil;
 NSArray *result = [moc executeFetchRequest: fetchRequest error: &error];
有没有办法让那些特殊的字符名出现在我上面描述的位置?在网上找不到关于这个的任何东西


非常感谢。

您应该使用UILocalizedIndexedCollation对条目进行排序并将其分类到各个部分。实现这一点的代码在问题中


UILocalizedIndexedCollation的构建是为了能够根据当前的语言设置对每种语言的单词进行分类。Á和A将放在A部分。

谢谢你的回答,我可以用另一种(简单的)方法解决这个问题

我只需修改NSSortDescriptor,如下所示:

[NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES selector: @selector(localizedCompare:)]

在iOS>=4.0中,应使用本地化标准比较: