<!--
{
  "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/record(_:named:sourceLocation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift Testing",
      "Testing"
    ],
    "preciseIdentifier" : "s:7Testing10AttachmentVAARi_zrlE6record_5named14sourceLocationyxn_SSSgAA06SourceF0VtFZ"
  },
  "title" : "record(_:named:sourceLocation:)"
}
-->

# record(_:named:sourceLocation:)

Attach a value to the current test.

```
static func record(_ attachableValue: consuming AttachableValue, named preferredName: String? = nil, sourceLocation: SourceLocation = #_sourceLocation)
```

## Parameters

`attachableValue`

The value to attach.

`preferredName`

The preferred name of the attachment to use when saving
it. If `nil`, the testing library attempts to generate a reasonable
filename for the attached value.

`sourceLocation`

The source location of the call to this function.

## Discussion

When `attachableValue` is an instance of a type that does not conform to
the [`Sendable`](https://developer.apple.com/documentation/swift/sendable)
protocol, the testing library calls its [`withUnsafeBytes(for:_:)`](/documentation/Testing/Attachable/withUnsafeBytes(for:_:))
immediately and records a copy of the resulting buffer instead. If
`attachableValue` throws an error when the testing library calls its
[`withUnsafeBytes(for:_:)`](/documentation/Testing/Attachable/withUnsafeBytes(for:_:)) function, the testing library
records that error as an issue in the current test.

This function creates a new instance of [`Attachment`](/documentation/Testing/Attachment) and immediately
attaches it to the current test.

---

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)