小编Sta*_*nko的帖子

排序NSDictionary的问题

我需要对字典的NSDictionary进行排序.看起来像:

{//dictionary
        RU = "110.1"; //key and value
        SG = "150.2"; //key and value
        US = "50.3"; //key and value
    }
Run Code Online (Sandbox Code Playgroud)

结果需要像:

 {//dictionary
            SG = "150.2"; //key and value
            RU = "110.1"; //key and value
            US = "50.3"; //key and value
        }
Run Code Online (Sandbox Code Playgroud)

我在尝试这个:

@implementation NSMutableDictionary (sorting)

-(NSMutableDictionary*)sortDictionary
{
    NSArray *allKeys = [self allKeys];
    NSMutableArray *allValues = [NSMutableArray array];
    NSMutableArray *sortValues= [NSMutableArray array];
    NSMutableArray *sortKeys= [NSMutableArray array];

    for(int i=0;i<[[self allValues] count];i++)
    {
        [allValues addObject:[NSNumber numberWithFloat:[[[self allValues] objectAtIndex:i] floatValue]]];   
    }



    [sortValues addObjectsFromArray:allValues]; …
Run Code Online (Sandbox Code Playgroud)

sorting iphone nsdictionary

1
推荐指数
1
解决办法
4838
查看次数

标签 统计

iphone ×1

nsdictionary ×1

sorting ×1