Contents

init(exporting:as:named:sourceLocation:)

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

Declaration

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 Exportedcontenttypes( :) on transferableValue and uses the first type the function returns that conforms to 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

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.