我需要反转我的 NSArray
。
举个例子:
[1,2,3,4,5]
必须变为:[5,4,3,2,1]
实现这一目标的最佳方法是什么?
最佳答案
如果您利用 NSArray
上的内置 reverseObjectEnumerator
方法和NSEnumerator
:
NSArray* reversedArray = [[startArray reverseObjectEnumerator] allObjects];
allObjects
is documented作为返回一个数组,其中包含尚未用 nextObject
遍历的对象,按顺序:
This array contains all the remaining objects of the enumerator in enumerated order.
https://stackoverflow.com/questions/586370/