sort NSDictionary values by key alphabetical order

后端 未结 4 1910
谎友^
谎友^ 2020-12-14 01:51

I can get an array of dictionary keys sorted by values, but how to I get an array of values sorted by dictionary keys? I\'ve been looking everywhere with no luck. Any help a

4条回答
  •  感情败类
    2020-12-14 02:22

    One way is to construct the array of sorted dictionary keys, then create another array of the values based on the array of keys:

    //Construct array of sorted keys
    NSArray keyarray = ... //etc
    
    NSMutableArray valuearray = [[NSMutableArray alloc] init];
    for (id key in keyarray) {
        [valuearray addObject:[dict objectForKey:key]];
    }
    

提交回复
热议问题