<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreVideo",
  "identifier" : "/documentation/CoreVideo/CVAttachmentAccess/subscript(dynamicMember:)-1ya6s",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Core Video"
    ],
    "preciseIdentifier" : "s:9CoreVideo18CVAttachmentAccessV13dynamicMemberqd_0_Sgs7KeyPathCyxmAA0c9CompositeG10DefinitionVyqd__qd_0_GG_tcAA0C14ModePreferenceRd__AA0C18ValueRepresentableRd_0_r0_luip"
  },
  "title" : "subscript(dynamicMember:)"
}
-->

# subscript(dynamicMember:)

Get or set composite attachment value as a property of this object.

```
subscript<ModePreference, Value>(dynamicMember keyPath: KeyPath<Keys.Type, CVAttachmentCompositeKeyDefinition<ModePreference, Value>>) -> Value? where ModePreference : CVAttachmentModePreference, Value : CVAttachmentValueRepresentable { get set }
```

## Overview

This subscript provides access to an attachment key as a property. The key to be accessed must be defined as a
static property on the `Keys` type. This accessor is intended to be used with legacy keys which are not grouped
together in a single container. For new keys, use [`CVAttachmentKeyDefinitions.Key`](/documentation/CoreVideo/CVAttachmentKeyDefinitions/Key) instead of using a composite
key group.

```swift
enum MyImageTag: CVAttachmentValueRepresentable {
	case int(Int)
	case string(String)

	static func makeFromRawAttachmentValue(_ repr: CVAttachmentRawValue) -> Self? {
		guard let kind: String = repr["com.app.MyImageTag.Kind"] else { return nil }
		switch kind {
		case "int":
			guard let value: Int = repr["com.app.MyImageTag.Value"] else { return nil }
			return .int(value)
		case "str":
			guard let value: String = repr["com.app.MyImageTag.Value"] else { return nil }
			return .string(value)
		default:
			return nil
		}
	}

	var rawAttachmentValueRepresentation: CVAttachmentRawValue {
		switch self {
		case .int(let value):
			[
				"com.app.MyImageTag.Kind": "int",
				"com.app.MyImageTag.Value": value,
			]
		case .string(let value):
			[
				"com.app.MyImageTag.Kind": "str",
				"com.app.MyImageTag.Value": value,
			]
		}
	}
}

extension CVPixelBufferAttachmentKeyDefinitions {
	/// A composite key definition which combines legacy top level raw keys
	static var myLegacyImageTag: CompositeKey<ShouldPropagate, MyImageTag> {
		["com.app.MyImageTag.Kind", "com.app.MyImageTag.Value"]
	}

	/// For new code, a single key should be used
	static var myImageTag: Key<ShouldPropagate, MyImageTag> {
		"com.app.MyImageTag"
	}
}

func inspect(attachments: borrowing CVAttachmentAccess<CVPixelBufferAttachmentKeyDefinitions>) {
	let value1: MyImageTag? = attachments.myLegacyImageTag
	let value2: MyImageTag? = attachments.myImageTag
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)