ios 反向 NSMutableArray
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5137006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reverse NSMutableArray
提问by system
What is the best/correct way to reverse an NSMutableArray?
反转 NSMutableArray 的最佳/正确方法是什么?
回答by Ajay
themutablearray=[[[themutablearray reverseObjectEnumerator] allObjects] mutableCopy];
回答by Prasad G
theMutableArray=[[[theMutableArray reverseObjectEnumerator] allObjects] mutableCopy];
回答by EI Captain v2.0
Here is the swiftversion of Reverse NSMutableArray
这是Reverse NSMutableArray的swift版本
mutablearray = NSMutableArray(array: YourMutablearray.reverseObjectEnumerator().allObjects).mutableCopy() as! NSMutableArray
In pure Swift, you can use reverse()
在纯 Swift 中,您可以使用 reverse()
let array = ["Apples", "Peaches", "Plums"]
for item in array.reverse() {
print("Found \(item)")
}
Source:hacking with swift
------ OR ------
- - - 或者 - - -
var a = [String]()
a.append("1")
a.append("2")
a.append("3")
print(Array(a.reverse())) // In swift 3.0, method is `reversed()`
回答by BHAVIK PANCHAL
For Swift 3
对于 Swift 3
let reversedArray = NSArray()
reversedArray = NSMutableArray(array:TableDataArr.reverseObjectEnumerator().allObjects).mutableCopy() as! NSMutableArray
回答by Josh O'Connor
Why all the complication? Use this:
为什么所有的并发症?用这个:
Swift 3:
斯威夫特 3:
let tasksArray = NSArray()
var reversedTaskArray = tasksArray.reversed() as NSArray
回答by sanjeev sharma
you can reverse nsmutablearray with the help of reverseObjectEnumerator. It will return you nsarray then you should create a nsmutablearray with the help of this nsarray
您可以在 reverseObjectEnumerator 的帮助下反转 nsmutablearray。它会返回你 nsarray 然后你应该在这个 nsarray 的帮助下创建一个 nsmutablearray
NSArray* reversedArray = [[TableDataArr reverseObjectEnumerator] allObjects];
TableDataArr = [NSMutableArray arrayWithArray:reversedArray];