Sort NSDictionary By property of object stored as value

前端 未结 2 900

I am storing data in NSMutableDictionary To store data received by web service.

I want to display data in alpha order but as we know Dictionary store da

2条回答
  •  心在旅途
    2021-01-18 12:52

    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"Object.Name" ascending:YES];
    [items sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
    

    Also,

    NSArray *ordered = [myDictionary keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2){
        return [obj1.name compare:obj2.name];
    }];
    

提交回复
热议问题