Monday, July 11, 2016

Reverse Array in Swift 2.2/3.0

To reverse an array in Swift 2.2 with Xcode 7.3.1:

var array = ["a","b","c","d","e","f","g"]
        
array = array.reverse()
        

print(array)

To reverse an array in Swift 3 with IBM Swift Sandbox (Swift 3.0 June 20, 2016):

var array = ["a","b","c","d","e","f","g"]

array = array.reversed()


print(array)

Result:


No comments:

Post a Comment