<!--
{
  "availability" : [
    "Swift: 6.3.0 -",
    "Xcode: 26.4.0 -",
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "swift: 6.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Attachment/record(_:named:as:sourceLocation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift Testing",
      "Testing"
    ],
    "preciseIdentifier" : "s:7Testing10AttachmentV6record_5named2as14sourceLocationyqd___SSSgAA21AttachableImageFormatVSgAA06SourceG0VtAA01_hI7WrapperCyqd__GRbzAA0hL0RzAA0h2AsI0Rd__lFZ"
  },
  "title" : "record(_:named:as:sourceLocation:)"
}
-->

# record(_:named:as:sourceLocation:)

Attach an image to the current test.

```
static func record<T>(_ image: T, named preferredName: String? = nil, as imageFormat: AttachableImageFormat? = nil, sourceLocation: SourceLocation = #_sourceLocation) where AttachableValue : _AttachableImageWrapper<T>, AttachableValue : AttachableWrapper, T : AttachableAsImage
```

## Parameters

`image`

The value to attach.

`preferredName`

The preferred name of the attachment when writing it to
a test report or to disk. If `nil`, the testing library attempts to
derive a reasonable filename for the attached value.

`imageFormat`

The image format with which to encode `image`.

`sourceLocation`

The source location of the call to this function.

## Discussion

This function creates a new instance of [`Attachment`](/documentation/Testing/Attachment) wrapping `image`
and immediately attaches it to the current test. The testing library uses
the image format that `imageFormat` specifies. Pass `nil` to let the testing
library select which image format to use. If you pass `nil`, the
image format that the testing library uses depends on the path extension
you specify in `preferredName`, if any. If you don’t specify a path
extension, or if the path extension you specify doesn’t correspond to an
image format the operating system knows how to write, the testing library
selects an appropriate image format for you.

---

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)