[英]iPhone CoreData: Sort with umlauts
我有一個應用程序從sqlite數據庫中獲取數據(國家列表)。 這些國家都是德語,包含變音符號,例如Ö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];
有沒有辦法讓這些特殊的字符名稱出現在我上面描述的位置? 在這上面沒有找到任何關於互聯網的東西......
非常感謝。
謝謝你的回答,我可以用另一種(簡單的)方式解決問題!
我只需要像這樣修改NSSortDescriptor:
[NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES selector: @selector(localizedCompare:)]
您應該使用UILocalizedIndexedCollation對條目進行排序和分類。 實現它的代碼在NSFetchedResultsController和UILocalizedIndexedCollation的問題中
UILocalizedIndexedCollation的構建是為了能夠在每種語言的基礎上根據當前語言設置對單詞進行分類。 Á和à將放在A部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.