Reverses the elements of the collection in place.
SDK
- Xcode 8.3+
Framework
- Swift Standard Library
Declaration
mutating func reverse()
Available when Self conforms to BidirectionalCollection .
Discussion
The following example reverses the elements of an array of characters:
var characters: [Character] = ["C", "a", "f", "é"]
characters.reverse()
print(characters)
// Prints "["é", "f", "a", "C"]
Complexity: O(n), where n is the number of elements in the collection.