Sort NSDictionary in ascending order

前端 未结 3 1602
孤城傲影
孤城傲影 2021-01-28 02:55

I am trying to sort an NSDictionary in ascending order. I am using this code:

NSDictionary *valDict = self.mGetDataDict[key][rowKey];

for (NSString         


        
3条回答
  •  -上瘾入骨i
    2021-01-28 03:25

    Try to use this one....

    // changes.......

    NSArray *valDict = [[self.mGetDataDict allValues] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    NSMutableDictionary *orderedDictionary=[[NSMutableDictionary alloc] init];
    
    for (NSString *valor in valDict)
    {
        for (NSString *clave in [yourDictionary allKeys])
        {
            if ([valor isEqualToString:[valDict valueForKey:clave]]) 
            {
                [orderedDictionary setValue:valor forKey:clave];
            }
        }
    }
    

提交回复
热议问题