<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core Video"
    ],
    "preciseIdentifier" : "s:9CoreVideo18CVAttachmentAccessV"
  },
  "title" : "CVAttachmentAccess"
}
-->

# CVAttachmentAccess

Provides access to the attachments of a buffer.

```
@dynamicMemberLookup struct CVAttachmentAccess<Keys> where Keys : CVAttachmentKeyDefinitions
```

## Overview

Lifetime of an instance of this type is tied to the lifetime of the buffer carrying attachments. The properties
of this object are dynamically resolved to the static properties of the `Keys` type.

For example, when custom attachment keys are defined as follows:

```swift
extension CVImageBufferAttachmentKeyDefinitions {
	static var imageBufferName: Key<ShouldPropagate, String> {
		"com.app.imageBufferName"
	}
}
extension CVPixelBufferAttachmentKeyDefinitions {
	static var pixelBufferNumber: Key<ShouldPropagate, Int> {
		"com.app.pixelBufferNumber"
	}
}
```

Both keys can be accessed as a property of an CVAttachmentAccess instance. As CVImageBufferAttachmentKeyDefinitions
is the superclass of CVPixelBufferAttachmentKeyDefinitions.

```swift
func inspect(attachments: borrowing CVAttachmentAccess<CVPixelBufferAttachmentKeyDefinitions>) {
	let value1: String? = attachments.imageBufferName
	let value2: Int? = attachments.pixelBufferNumber
}
```

It is also possible to access the keys by directly specifying raw string value:

```swift
let num: Int? = pixelBuffer.attachments["com.app.pixelBufferNumber"]
pixelBuffer.attachments["com.app.pixelBufferNumber"] = (100, .shouldPropagate)

// To set an attachment value by ignoring the preferred mode requires using rawValue of the key
pixelBuffer.attachments[CVPixelBufferAttachmentKeyDefinitions.displayDimensions.rawValue] = (CGSize(width: 600, height: 400), .shouldNotPropagate)
```

## Topics

### Instance Methods

[`func attachedMode(of: KeyPath<Keys.Type, CVAttachmentKeyDefinitionWithDefault<some CVAttachmentModePreference, some CVAttachmentValueRepresentable & Equatable & Sendable>>) -> CVAttachmentMode?`](/documentation/CoreVideo/CVAttachmentAccess/attachedMode(of:)-79dr)

Returns the propagation mode of an attachment you identify with a key path to a key definition that supplies a default, without retrieving the value.

[`func attachedMode(of: KeyPath<Keys.Type, CVAttachmentKeyDefinition<some CVAttachmentModePreference, some CVAttachmentValueRepresentable>>) -> CVAttachmentMode?`](/documentation/CoreVideo/CVAttachmentAccess/attachedMode(of:)-9g9h6)

Returns the propagation mode of an attachment you identify with a key path to a key definition, without retrieving the value.

[`func attachedMode(of: String) -> CVAttachmentMode?`](/documentation/CoreVideo/CVAttachmentAccess/attachedMode(of:)-m49)

Returns the propagation mode of an attachment you identify by its raw key string, without retrieving the value.

[`func copy() -> CVAttachmentContainer<Keys>`](/documentation/CoreVideo/CVAttachmentAccess/copy())

Creates a copy all propagated and non-propagated attachments.

[`func propagate(from: borrowing CVAttachmentAccess<Keys>)`](/documentation/CoreVideo/CVAttachmentAccess/propagate(from:))

Copies all propagated attachment values from another buffer.

[`func removeAll()`](/documentation/CoreVideo/CVAttachmentAccess/removeAll())

Removes all attachments.

[`func update(from: CVAttachmentContainer<Keys>)`](/documentation/CoreVideo/CVAttachmentAccess/update(from:))

Updates propagated and non-propagated attachment values using the provided container.

### Subscripts

[`subscript<Value>(String, as _: Value.Type) -> (value: Value, mode: CVAttachmentMode)?`](/documentation/CoreVideo/CVAttachmentAccess/subscript(_:as:))

Get or set attachment value associated with a string key

[`subscript<ModePreference, Value>(dynamicMember _: KeyPath<Keys.Type, CVAttachmentCompositeKeyDefinition<ModePreference, Value>>) -> Value?`](/documentation/CoreVideo/CVAttachmentAccess/subscript(dynamicMember:)-1ya6s)

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

[`subscript<ModePreference, Value>(dynamicMember _: KeyPath<Keys.Type, CVAttachmentKeyDefinitionWithDefault<ModePreference, Value>>) -> Value`](/documentation/CoreVideo/CVAttachmentAccess/subscript(dynamicMember:)-38ve9)

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

[`subscript<ModePreference, Value>(dynamicMember _: KeyPath<Keys.Type, CVAttachmentKeyDefinition<ModePreference, Value>>) -> Value?`](/documentation/CoreVideo/CVAttachmentAccess/subscript(dynamicMember:)-9egcs)

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

---

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)