Sorting an NSArray of NSString

前端 未结 5 1669
名媛妹妹
名媛妹妹 2020-12-16 12:36

Can someone please show me the code for sorting an NSMutableArray? I have the following NSMutableArray:

NSMutableArray *arr = [[NSMutableArray alloc] init];
         


        
5条回答
  •  眼角桃花
    2020-12-16 12:50

    IMHO, easiest way to sort such array is

    [arr sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self.intValue" ascending:YES]]]
    

    If your array contains float values, just change key to self.floatValue or self.doubleValue

提交回复
热议问题