<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuickLookUI",
  "identifier" : "/documentation/QuickLookUI/QLPreviewReplyAttachment",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Quick Look UI"
    ],
    "preciseIdentifier" : "c:objc(cs)QLPreviewReplyAttachment"
  },
  "title" : "QLPreviewReplyAttachment"
}
-->

# QLPreviewReplyAttachment

An attachment for a Quick Look preview reply that provides additional content for the system to display a preview.

```
class QLPreviewReplyAttachment
```

## Overview

When providing a data-based Quick Look preview with HTML, use [`QLPreviewReplyAttachment`](/documentation/QuickLookUI/QLPreviewReplyAttachment) to include images, CSS, and other linked content in the HTML of the preview.

Reference content in your html using the `CID` notation for the reference. For instance, if your HTML preview response includes an image, create a [`QLPreviewReplyAttachment`](/documentation/QuickLookUI/QLPreviewReplyAttachment) with the image, add it the reply’s [`attachments`](/documentation/QuickLookUI/QLPreviewReply/attachments) with an associated string, and reference the image with the associated string, prefixed by `cid:`. The following example illustrates returning HTML as a preview reply with an image as an attachment:

```swift
let reply = QLPreviewReply(dataOfContentType: .html,
                           contentSize: CGSize(width: 750, height: 500)) { htmlReply in
    let content = """
                  <html>
                  <head></head>
                  <body>
                  <h1>Preview</h1>
                  <img src=\"cid:exampleImage\" width=\"400\">
                  </body>
                  </html>
                  """
    guard let contentData = content.data(using: .utf8) else {
        throw PreviewError.previewSetupFailure("Unable to encode preview content")
    }
    guard let imageFileURL = Bundle.main.url(forResource: "yourImage",
                                             withExtension: "jpg") else {
        throw PreviewError.previewSetupFailure("unable to load image")
    }
    let imageData = try Data(contentsOf: imageFileURL)
    
    htmlReply.attachments["exampleImage"] = QLPreviewReplyAttachment(data: imageData,
                                                                     contentType: .jpeg)
    return contentData
}
reply.title = "HTML Preview Example"
```

## Topics

### Creating a preview reply attachment

[`-  initWithData:contentType:`](/documentation/QuickLookUI/QLPreviewReplyAttachment/init(data:contentType:))

Creates a preview reply attachment with the specified type.

### Inspecting a preview reply attachment

[`contentType`](/documentation/QuickLookUI/QLPreviewReplyAttachment/contentType)

The content type of the preview attachment.

[`data`](/documentation/QuickLookUI/QLPreviewReplyAttachment/data)

The data of the preview attachment.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)