要获得数组的反向副本,请使用reverseObjectEnumerator
查看danielpunkass' solution.
要反转可变数组,可以在代码中添加以下类别:
@implementation NSMutableArray (Reverse)
- (void)reverse {
if ([self count] <= 1)
return;
NSUInteger i = 0;
NSUInteger j = [self count] - 1;
while (i < j) {
[self exchangeObjectAtIndex:i
withObjectAtIndex:j];
i++;
j--;
}
}
@end