---
title: "exchange(_:with:)"
framework: swift
role: symbol
role_heading: Function
path: "swift/exchange(_:with:)"
---

# exchange(_:with:)

Replaces the value of a mutable value with the supplied new value, returning the original.

## Declaration

```swift
func exchange<T>(_ item: inout T, with newValue: consuming T) -> T where T : ~Copyable
```

## Parameters

- `item`: A mutable binding.
- `newValue`: The new value of item.

## Return Value

Return Value The original value of item.

## See Also

### Memory Access

- [withUnsafePointer(to:_:)](swift/withunsafepointer(to:_:)-9fjn6.md)
- [withUnsafePointer(to:_:)](swift/withunsafepointer(to:_:)-35wrn.md)
- [withUnsafeMutablePointer(to:_:)](swift/withunsafemutablepointer(to:_:).md)
- [withUnsafeBytes(of:_:)](swift/withunsafebytes(of:_:)-5zxtl.md)
- [withUnsafeBytes(of:_:)](swift/withunsafebytes(of:_:)-5gesg.md)
- [withUnsafeMutableBytes(of:_:)](swift/withunsafemutablebytes(of:_:).md)
- [withUnsafeTemporaryAllocation(of:capacity:_:)](swift/withunsafetemporaryallocation(of:capacity:_:).md)
- [withUnsafeTemporaryAllocation(byteCount:alignment:_:)](swift/withunsafetemporaryallocation(bytecount:alignment:_:).md)
- [swap(_:_:)](swift/swap(_:_:).md)
