---
title: "record(_:named:as:sourceLocation:)"
framework: testing
role: symbol
role_heading: Type Method
path: "testing/attachment/record(_:named:as:sourcelocation:)"
---

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

Attach an image to the current test.

## Declaration

```swift
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

Discussion This function creates a new instance of 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.

## See Also

### Attaching images to tests

- [AttachableAsImage](testing/attachableasimage.md)
- [AttachableImageFormat](testing/attachableimageformat.md)
- [init(_:named:as:sourceLocation:)](testing/attachment/init(_:named:as:sourcelocation:).md)
