Instance Method

removeAll(keepingCapacity:)

Removes all elements from the array.

Declaration

mutating func removeAll(keepingCapacity keepCapacity: Bool = false)

Parameters

keepCapacity

Pass true to keep the existing capacity of the array after removing its elements. The default value is false.

Discussion

Complexity: O(n), where n is the length of the array.

Relationships

See Also

Removing Elements

func remove(at: Int) -> Element

Removes and returns the element at the specified position.

func removeFirst() -> Element

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() -> Element

Removes and returns the last element of the collection.

func removeLast(Int)

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

func removeSubrange(Range<Int>)

Removes the elements in the specified subrange from the collection.

func removeSubrange<R>(R)

Removes the elements in the specified subrange from the collection.

func removeAll(where: (Element) -> Bool)

Removes all the elements that satisfy the given predicate.

func popLast() -> Element?

Removes and returns the last element of the collection.