---
title: "init(exporting:as:named:sourceLocation:)"
framework: testing
role: symbol
role_heading: Initializer
path: "testing/attachment/init(exporting:as:named:sourcelocation:)"
---

# init(exporting:as:named:sourceLocation:)

Initialize an instance of this type that encloses the given transferable value.

## Declaration

```swift
init<T>(exporting transferableValue: T, as contentType: UTType? = nil, named preferredName: String? = nil, sourceLocation: SourceLocation = #_sourceLocation) async throws where AttachableValue == _AttachableTransferableWrapper<T>, T : Transferable
```

## Parameters

- `transferableValue`: The value that will be attached to the output of the test run.
- `contentType`: The content type with which to export transferableValue. If this argument is nil, the testing library calls https://developer.apple.com/documentation/coretransferable/transferable/exportedcontenttypes(_:) on transferableValue and uses the first type the function returns that conforms to https://developer.apple.com/documentation/uniformtypeidentifiers/uttype-swift.struct/data.
- `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 initializer. This value is used when recording issues associated with the attachment.

## Discussion

Discussion note: Any error that occurs while exporting transferableValue. Use this initializer to create an instance of Attachment from a value that conforms to the Transferable protocol. let menu = FoodTruck.menu let attachment = try await Attachment(exporting: menu, as: .pdf) Attachment.record(attachment) When you call this initializer and pass it a transferable value, it calls exported(as:) on that value. This operation may take some time, so this initializer suspends the calling task until it is complete.
