Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS中的密钥排序_Ios_Sorting_Dictionary_Key - Fatal编程技术网

IOS中的密钥排序

IOS中的密钥排序,ios,sorting,dictionary,key,Ios,Sorting,Dictionary,Key,我正在将密钥加载到ios中的pickercontrol。 我的问题是我不能把钥匙按字母顺序排序 代码从未排序的:诺德芬、斯文堡、尼堡、兰格兰、阿森斯、克特明德、米德尔法特、奥登塞、奥德塞、奥德塞、法博格、米德芬,到排序的:奥德塞、斯文堡、尼堡、兰格兰、克特明德、诺德芬、米德尔法特、阿森斯、奥登塞、法博格、法博格、米德芬 NSBundle *KSbundle = [NSBundle mainBundle]; NSURL *KSplistURL = [KSbundle URLForResource:

我正在将密钥加载到ios中的pickercontrol。 我的问题是我不能把钥匙按字母顺序排序

代码从未排序的:诺德芬、斯文堡、尼堡、兰格兰、阿森斯、克特明德、米德尔法特、奥登塞、奥德塞、奥德塞、法博格、米德芬,到排序的:奥德塞、斯文堡、尼堡、兰格兰、克特明德、诺德芬、米德尔法特、阿森斯、奥登塞、法博格、法博格、米德芬

NSBundle *KSbundle = [NSBundle mainBundle];
NSURL *KSplistURL = [KSbundle URLForResource:@"KommunerStedtillæg" 
                           withExtension:@"plist"];
NSDictionary *KSdictionary = [NSDictionary 
                            dictionaryWithContentsOfURL:KSplistURL];


NSArray *KSkeys = [[KSdictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];


NSMutableDictionary *KSnewDict = [NSMutableDictionary dictionary];

for (id key in KSkeys)
    [KSnewDict setObject:[KSdictionary objectForKey:key] forKey:key];

kommunerKeys = [KSnewDict allKeys];
kommunerValues = [KSnewDict allValues];
从这里开始


添加您需要的选项

您可能正在寻找以下选项:

 [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

仅仅比较是不够的。

看起来就像是在看kommunerKeys,但字典中键的顺序没有定义(请参阅)。在添加之前对它们进行排序对您没有帮助

尝试
localizedCaseInsensitiveCompare:
而不是
compare:
?现在我得到了:奥登塞、斯文堡、尼堡、兰格兰、伊尔罗、阿森米德尔法特、克特明德、诺德芬、法博格米德芬。现在我得到了:伊尔罗、斯文堡、尼堡、兰格兰、克特明德、诺德芬、米德尔法特、阿森、奥登塞、,Faaborg-Midtfyn.也许是名字中的特殊字符问题?为了确保这一点,只插入ASCII字符,然后查看数组是否已排序。这一点很好。其他人(包括我!)都被这些特殊的角色分散了注意力
 [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];