<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreVideo",
  "identifier" : "/documentation/CoreVideo/CVBufferSetAttachment(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Video"
    ],
    "preciseIdentifier" : "c:@F@CVBufferSetAttachment"
  },
  "title" : "CVBufferSetAttachment(_:_:_:_:)"
}
-->

# CVBufferSetAttachment(_:_:_:_:)

Sets or adds an attachment to a Core Video buffer.

```
func CVBufferSetAttachment(_ buffer: CVBuffer, _ key: CFString, _ value: CFTypeRef, _ attachmentMode: CVAttachmentMode)
```

## Parameters

`buffer`

The buffer on which to add or set an attachment.

`key`

A string that identifies the attachment, which can be of any <doc://com.apple.documentation/documentation/CoreFoundation/CFTypeRef>. See [CVBuffer Attachment Keys](/documentation/CoreVideo/cvbuffer-attachment-keys) and [Image Buffer Attachment Keys](/documentation/CoreVideo/image-buffer-attachment-keys) for predefined values.

`value`

The attachment in the form of a Core Foundation object. If this parameter is `NULL`, the function returns an error.

`attachmentMode`

The attachment mode for this attachment. See [`CVAttachmentMode`](/documentation/CoreVideo/CVAttachmentMode) for possible values. Any given attachment key may exist in only one mode at a time.

## Discussion

You can attach any Core Foundation object to a Core Video buffer to store additional information.

If it doesn’t exist for the buffer object, the system adds a new attachment. If the key does exist, the system replaces the existing attachment. In both cases, the system increases the retain count of the attachment.

You can also set attachments when creating a buffer by specifying them in the [`kCVBufferPropagatedAttachmentsKey`](/documentation/CoreVideo/kCVBufferPropagatedAttachmentsKey) or [`kCVBufferNonPropagatedAttachmentsKey`](/documentation/CoreVideo/kCVBufferNonPropagatedAttachmentsKey) attributes.

To retrieve attachments, use the [`CVBufferGetAttachment(_:_:_:)`](/documentation/CoreVideo/CVBufferGetAttachment(_:_:_:)) or [`CVBufferGetAttachments(_:_:)`](/documentation/CoreVideo/CVBufferGetAttachments(_:_:)) functions.

---

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)