<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMSetAttachment(_:key:value:attachmentMode:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMSetAttachment"
  },
  "title" : "CMSetAttachment(_:key:value:attachmentMode:)"
}
-->

# CMSetAttachment(_:key:value:attachmentMode:)

Sets or adds an attachment to an attachment bearer object.

```
func CMSetAttachment(_ target: CMAttachmentBearer, key: CFString, value: CFTypeRef?, attachmentMode: CMAttachmentMode)
```

## Parameters

`target`

The `CMAttachmentBearer` object on which to add or set attachments.

`key`

A `CFString` key identifying the desired attachment.

`value`

A Core Foundation object attachment. If this parameter is `NULL`, the function returns an error.

`attachmentMode`

Specifies the attachment mode for this attachment. Any given attachment key may exist in only one mode at a time.

## Discussion

You can attach any Core Foundation object to a `CMAttachmentBearer` object to store additional information. `CMSetAttachment` stores an attachment identified by a key. If the key doesn’t currently exist for the `CMAttachmentBearer` object when you call this function, the function adds the new attachment. If the key does exist, the function replaces the existing attachment. In both cases the function increments the retain count of the attachment. The value can be any `CFType` but a `NULL` value results in an error. Given a <doc://com.apple.documentation/documentation/CoreVideo/CVBuffer>, `CMSetAttachment` is equivalent to `CVBufferSetAttachment`.

---

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)