---
title: "subscript(_:)"
framework: swiftui
role: symbol
role_heading: Instance Subscript
path: "swiftui/transaction/subscript(_:)"
---

# subscript(_:)

Accesses the transaction value associated with a custom key.

## Declaration

```swift
subscript<K>(key: K.Type) -> K.Value where K : TransactionKey { get set }
```

## Overview

Overview Create custom transaction values by defining a key that conforms to the TransactionKey protocol, and then using that key with the subscript operator of the Transaction structure to get and set a value for that key: private struct MyTransactionKey: TransactionKey {     static let defaultValue = false }

extension Transaction {     var myCustomValue: Bool {         get { self[MyTransactionKey.self] }         set { self[MyTransactionKey.self] = newValue }     } }

## See Also

### Getting information about a transaction

- [isContinuous](swiftui/transaction/iscontinuous.md)
- [scrollTargetAnchor](swiftui/transaction/scrolltargetanchor.md)
- [tracksVelocity](swiftui/transaction/tracksvelocity.md)
