---
title: TransactionKey
framework: swiftui
role: symbol
role_heading: Protocol
path: swiftui/transactionkey
---

# TransactionKey

A key for accessing values in a transaction.

## Declaration

```swift
protocol TransactionKey
```

## Overview

Overview You can create custom transaction values by extending the Transaction structure with new properties. First declare a new transaction key type and specify a value for the required defaultValue property: private struct MyTransactionKey: TransactionKey {     static let defaultValue = false } The Swift compiler automatically infers the associated Value type as the type you specify for the default value. Then use the key to define a new transaction value property: extension Transaction {     var myCustomValue: Bool {         get { self[MyTransactionKey.self] }         set { self[MyTransactionKey.self] = newValue }     } } Clients of your transaction value never use the key directly. Instead, they use the key path of your custom transaction value property. To set the transaction value for a change, wrap that change in a call to withTransaction: withTransaction(\.myCustomValue, true) {     isActive.toggle() } To use the value from inside MyView or one of its descendants, use the transaction(_:) view modifier: MyView()     .transaction { transaction in         if transaction.myCustomValue {             transaction.animation = .default.repeatCount(3)         }     }

## Topics

### Setting a default value

- [defaultValue](swiftui/transactionkey/defaultvalue.md)
- [Value](swiftui/transactionkey/value.md)

## See Also

### Moving an animation to another view

- [withTransaction(_:_:)](swiftui/withtransaction(_:_:).md)
- [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)
