Instance Property

last

The last element of the collection.

Declaration

var last: Character? { get }

Discussion

If the collection is empty, the value of this property is nil.

let numbers = [10, 20, 30, 40, 50]
if let lastNumber = numbers.last {
    print(lastNumber)
}
// Prints "50"

Complexity: O(1)

See Also

Getting Characters and Bytes

subscript(String.Index) -> Character

Accesses the character at the given position.

var first: Character?

The first element of the collection.

func randomElement() -> Character?

Returns a random element of the collection.

func randomElement<T>(using: inout T) -> Character?

Returns a random element of the collection, using the given generator as a source for randomness.