How to sort an array which contains Dictionaries?

前端 未结 5 378
Happy的楠姐
Happy的楠姐 2020-12-30 20:05

I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values?

5条回答
  •  既然无缘
    2020-12-30 20:55

    The above shared answer by Bavarious helped me.Just want to add one more thing.If you want to sort a mutable array use something like the below code

    NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName];
    NSMutableArray *sortedArray = [[NSMutableArray sortedArrayUsingDescriptors:sortDescriptors]mutableCopy];
    

提交回复
热议问题