我想從核心數據模型中獲取已排序的本地化數據。我的代碼:本地化排序的iPhone提取請求
NSEntityDescription *entityDescription = [NSEntityDescription entityForName: entityDescriptionValue
inManagedObjectContext: context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: entityDescription];
[fetchRequest setPredicate: predicate];
NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES selector: @selector(localizedCompare:)];
[fetchRequest setSortDescriptors: [NSArray arrayWithObject: sortBy]];
[sortBy release];
但是,當我得到的對象,他們仍然排序與原始值(非本地化的數據)。
我在做什麼不對?
你可以舉兩個'name'值不能比較/排序的例子嗎? –
在所有情況下,您確定數據的排序是基於區域設置嗎?它可能正確排序。 – TechZen
例如,國名:「英國,法國,德國」。當我將語言設置爲葡萄牙語時,我得到的順序是:「Inglaterra,França,Alemanha」。就像我沒有使用localizedCompare:選擇器來排序數據一樣。 –