Contents

subscript(_:)

Accesses the transaction value associated with a custom key.

Declaration

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

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