<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP_vswap",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@vDSP_vswap"
  },
  "title" : "vDSP_vswap"
}
-->

# vDSP_vswap

Swaps the elements of two single-precision vectors using the specified stride.

```
extern void vDSP_vswap(float *__A, vDSP_Stride __IA, float *__B, vDSP_Stride __IB, vDSP_Length __N);
```

## Parameters

`__A`

The input vector.

`__IA`

The distance between the elements in the input vector.

`__B`

The output vector.

`__IB`

The distance between the elements in the output vector.

`__N`

The number of elements that the operation swaps.

## 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]
    
    let stride = 1
    let n = vDSP_Length(4)
    
    vDSP_vswap(&vectorA, stride,
               &vectorB, stride,
               n)
    
    print(vectorA) // Prints "[2.0, 4.0, 6.0, 8.0]".
    print(vectorB) // Prints "[1.0, 3.0, 5.0, 7.0]".
```

---

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)