---
title: "swapAt(_:_:)"
framework: Swift
role: symbol
role_heading: Instance Method
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+, watchOS 27.0+]
path: "swift/uniquearray/swapat(_:_:)"
---

# swapAt(_:_:)

Exchanges the values at the specified indices of the array.

## Declaration

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

## Parameters

- `i`: The index of the first value to swap.
- `j`: The index of the second valud to swap.

## Discussion

Discussion Both parameters must be valid indices of the array and not equal to endIndex. Passing the same index as both i and j has no effect. note: O(1)
