Sorting an NSArray of NSString

前端 未结 5 1655
名媛妹妹
名媛妹妹 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

    You should use this method:

    [arr sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
    

    in a NSArray or:

    [arr sortUsingSelector:@selector(caseInsensitiveCompare:)];
    

    in a "inplace" sorting NSMutableArray

    The comparator should return one of this values:

    • NSOrderedAscending
    • NSOrderedDescending
    • NSOrderedSame

提交回复
热议问题