<!--
{
  "availability" : [
    "Swift: 6.2.0 -",
    "Xcode: 26.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Attachment",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing10AttachmentV"
  },
  "title" : "Attachment"
}
-->

# Attachment

A type describing values that can be attached to the output of a test run
and inspected later by the user.

```
struct Attachment<AttachableValue> where AttachableValue : Attachable, AttachableValue : ~Copyable
```

## Overview

To create an attachment, you need a value of some type that conforms to
[`Attachable`](/documentation/Testing/Attachable). Initialize an instance of [`Attachment`](/documentation/Testing/Attachment) with that value
and, optionally, a preferred filename to use when saving the attachment. To
record the attachment, call [`record(_:sourceLocation:)`](/documentation/Testing/Attachment/record(_:sourceLocation:)).
Alternatively, pass your attachable value directly to [`record(_:named:sourceLocation:)`](/documentation/Testing/Attachment/record(_:named:sourceLocation:)).

## Relationships

### Conforms To

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

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

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

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

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

---

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)