倒序操作


NSMutableArray *originalArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
NSArray* reversedArray = [[originalArray reverseObjectEnumerator] allObjects];
    
NSLog(@"originalArray --- %@",originalArray);
NSLog(@"reversedArray --- %@",reversedArray);


运行结果

20170228131301811

乱序操作


- (void)randomArray{
    
    NSArray *array=@[@"1",@"2",@"3",@"4",@"5",@"6",@"7"];
    NSLog(@"originalArray----%@", array);

    array = [array sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
        int seed = arc4random_uniform(2);
        if (seed) {
            return [str1 compare:str2];
        } else {
            return [str2 compare:str1];
        }
    }];
    NSLog(@"randomArray----%@", array);

} 

运行结果

20170228131301812