Contents

setCapacity(_:)

Grow or shrink the capacity of a unique array instance without discarding its contents.

Declaration

mutating func setCapacity(_ newCapacity: Int)

Parameters

  • newCapacity:

    The desired new capacity. newCapacity must be greater than or equal to the current count.

Discussion

This operation replaces the array’s storage buffer with a newly allocated buffer of the specified capacity, moving all existing elements to its new storage. The old storage is then deallocated.