How to sort numbers in NSArray?

前端 未结 5 865
深忆病人
深忆病人 2021-02-03 11:55

I can\'t piece together how to do this.

I fetch my array from a plist, this array is full of numbers (as set in the plist). Now al I need to do is sort them so they are

5条回答
  •  长情又很酷
    2021-02-03 12:35

    It work for me:

    NSSortDescriptor *sortIdClient = 
    [NSSortDescriptor sortDescriptorWithKey:@"campaignValue"
                                  ascending:NO
                                 comparator: ^(id obj1, id obj2){
    
        return [obj1 compare:obj2 options:NSNumericSearch];
    
     }];
    
    NSArray *sortDescriptors = @[sortIdClient];
    
    NSArray *arrTemp = [self.allCampaignsList sortedArrayUsingDescriptors:sortDescriptors];
    

提交回复
热议问题