---
title: "withTransaction(_:_:_:)"
framework: swiftui
role: symbol
role_heading: Function
path: "swiftui/withtransaction(_:_:_:)"
---

# withTransaction(_:_:_:)

Executes a closure with the specified transaction key path and value and returns the result.

## Declaration

```swift
func withTransaction<R, V>(_ keyPath: WritableKeyPath<Transaction, V>, _ value: V, _ body: () throws -> R) rethrows -> R
```

## Parameters

- `keyPath`: A key path that indicates the property of the doc://com.apple.SwiftUI/documentation/SwiftUI/Transaction structure to update.
- `value`: The new value to set for the item specified by keyPath.
- `body`: A closure to execute.

## Return Value

Return Value The result of executing the closure with the specified transaction value.

## See Also

### Moving an animation to another view

- [withTransaction(_:_:)](swiftui/withtransaction(_:_:).md)
- [transaction(_:)](swiftui/view/transaction(_:).md)
- [transaction(value:_:)](swiftui/view/transaction(value:_:).md)
- [transaction(_:body:)](swiftui/view/transaction(_:body:).md)
- [Transaction](swiftui/transaction.md)
- [Entry()](swiftui/entry().md)
- [TransactionKey](swiftui/transactionkey.md)
