怎样才能对数组中的这些值进行倒序排列呢?
_gradientArrayToWhite = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
怎样才能对数组中的这些值进行倒序排列呢?
_gradientArrayToWhite = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
使用NSArray的排序方法之一
NSArray * sorted = [_gradientArrayToWhite sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 integerValue] < [obj2 integerValue];
}];
NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],[NSNumber numberWithInt:3],[NSNumber numberWithInt:4],[NSNumber numberWithInt:5],[NSNumber numberWithInt:6],[NSNumber numberWithInt:7],[NSNumber numberWithInt:8],[NSNumber numberWithInt:9],[NSNumber numberWithInt:10], nil];
在这里你也可以像这样直接使用你的数组
NSArray *arr1 = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", nil];
NSArray *revArr = [[arr reverseObjectEnumerator] allObjects];
Result = <__NSArrayM 0x71348e0>(
10,
9,
8,
7,
6,
5,
4,
3,
2,
1
)