Sorting an NSArray of NSString

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

    It's pretty simple to write your own comparison method for strings:

    @implementation NSString(compare)
    
    -(NSComparisonResult)compareNumberStrings:(NSString *)str {
        NSNumber * me = [NSNumber numberWithInt:[self intValue]];
        NSNumber * you = [NSNumber numberWithInt:[str intValue]];
    
        return [you compare:me];
    }
    
    @end
    

提交回复
热议问题