Instance Method

swapAt(_:_:)

Exchanges the values at the specified indices of the collection.

Declaration

mutating func swapAt(_ i: Int, _ j: Int)

Parameters

i

The index of the first value to swap.

j

The index of the second value to swap.

Discussion

Both parameters must be valid indices of the collection that are not equal to endIndex. Calling swapAt(_:_:) with the same index as both i and j has no effect.

Complexity: O(1)

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software