How can I print the following array in reverse order?
var toDoListReverse = ["Take out garbage", "Pay bills", "Cross off finished items"]
How can I print the following array in reverse order?
var toDoListReverse = ["Take out garbage", "Pay bills", "Cross off finished items"]
Here is code for swift 3
let array = ["IOS A", "IOS B", "IOS C"]
for item in array.reversed() {
print("Found \(item)")
}
print the array in reverse order
Like this:
toDoListReverse.reversed().forEach {print($0)}
Swift 4
let numbers = [10, 50, 40]
for number in numbers.reversed() {
print(number)
}
// We can reverse an Array without allocating new space for its elements by calling this reversed() method.