Instance Method

removeLast()

Removes and returns the last element of the collection.

Declaration

@discardableResult mutating func removeLast() -> Bound

Return Value

The last element of the collection.

Discussion

The collection must not be empty. To remove the last element of a collection that might be empty, use the popLast() method instead.

Complexity: O(1)

See Also

Excluding Elements

func dropFirst(Int) -> Range<Bound>

Returns a subsequence containing all but the given number of initial elements.

func dropLast(Int) -> Range<Bound>

Returns a subsequence containing all but the specified number of final elements.

func drop(while: (Bound) -> Bool) -> Range<Bound>

Returns a subsequence by skipping elements while predicate returns true and returning the remaining elements.

func popFirst() -> Bound?

Removes and returns the first element of the collection.

func popLast() -> Bound?

Removes and returns the last element of the collection.

func removeFirst() -> Bound

Removes and returns the first element of the collection.

func removeFirst(Int)

Removes the specified number of elements from the beginning of the collection.

func removeLast(Int)

Removes the given number of elements from the end of the collection.