---
title: "attach(contentKey:)"
framework: coremedia
role: symbol
role_heading: Instance Method
path: "coremedia/cmreadysamplebuffer/attach(contentkey:)"
---

# attach(contentKey:)

Attaches an AVContentKey to a CMReadySampleBuffer for the purpose of content decryption. The client is expected to attach AVContentKeys to CMReadySampleBuffers that have been created by the client for enqueueing with AVSampleBufferDisplayLayer or AVSampleBufferAudioRenderer, for which the AVContentKeySpecifier matches indications of suitability that are available to the client according to the content key system that’s in use.

## Declaration

```swift
mutating func attach(contentKey: AVContentKey) throws
```

## Parameters

- `contentKey`: The content key to be attached.

## Discussion

Discussion note: Describes the reason for failure to attach the content key.
