<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/swapElements(_:_:)-96xn7",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO12swapElementsyyxz_q_ztAA0A13MutableBufferRzAaER_Sf7ElementRtzSfAFRt_r0_lFZ"
  },
  "title" : "swapElements(_:_:)"
}
-->

# swapElements(_:_:)

Swaps the elements of two single-precision vectors.

```
static func swapElements<T, U>(_ vectorA: inout T, _ vectorB: inout U) where T : AccelerateMutableBuffer, U : AccelerateMutableBuffer, T.Element == Float, U.Element == Float
```

## Parameters

`vectorA`

The first vector.

`vectorB`

The second vector.

## Discussion

The following code swaps the elements in `vectorA` with those in `vectorB`:

```swift
var vectorA: [Float] = [1, 3, 5, 7]
var vectorB: [Float] = [2, 4, 6, 8]

vDSP.swapElements(&vectorA,
                  &vectorB)

// Prints "[2.0, 4.0, 6.0, 8.0]".
print(vectorA)

// Prints "[1.0, 3.0, 5.0, 7.0]".
print(vectorB)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)