<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Synchronization/Atomic/exchange(_:ordering:)-8ip0d",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Synchronization"
    ],
    "preciseIdentifier" : "s:15Synchronization6AtomicVA2A18_Atomic8BitStorageV0B14RepresentationRtzrlE8exchange_8orderingxxn_AA0B14UpdateOrderingVtF"
  },
  "title" : "exchange(_:ordering:)"
}
-->

# exchange(_:ordering:)

Atomically sets the current value to `desired` and returns the original
value, applying the specified memory ordering.

```
func exchange(_ desired: consuming Value, ordering: AtomicUpdateOrdering) -> Value
```

## Parameters

`desired`

The desired new value.

`ordering`

The memory ordering to apply on this operation.

## Return Value

The original value.

---

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)