使用其中一个键内的值对NSDictionaries数组进行排序
这个问题在这里已经有了答案:
使用以下内容;
NSArray *sortedArray;
sortedArray = [unsortedArray sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *first, NSDictionary *second) {
    // Calculate distances for each dictionary from the device
    // ...
    return [firstDistance compare:secondDistance];
}];
不幸的是,你不能排序NSDictionary对象。 你应该创建NSMutableArray并对其进行排序。
看到这个 - 集合编程主题 - 排序数组
更新:你可以使用例如NSArray的这种方法来排序字典数组:
sortedArray = [someArray sortedArrayUsingFunction:compareElements context:NULL];
compareElements函数示例:
NSInteger compareElements (id num1, id num2, void *context)
{
    int v1 = [[num1 objectForKey:@"distance"] integerValue];
    int v2 = [[num2 objectForKey:@"distance"] integerValue];
    if (v1 < v2)
        return NSOrderedAscending;
    else if (v1 > v2)
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}
                        链接地址: http://www.djcxy.com/p/70809.html
                        上一篇: Sort array of NSDictionaries by a value inside one of the keys
