Contents

media(_:as:)

Loads the media data of this metadata for an attachment as the specified Transferable type if possible.

Declaration

nonisolated func media<Media>(_ attachment: LinkMetadata.Attachment, as type: Media.Type) async throws -> Media? where Media : Transferable

Parameters

  • attachment:

    The kind of attachment to access, such as .image, .icon, and .video.

  • type:

    The Transferable type to try to load the media data into. This type must support the content type of the attachment.

Return Value

A value of the Transferable type produced by the media data, or nil if there is no media data for the attachment as that type.

Discussion

For example, PNG image data can be extracted as a specific type from the metadata if available:

let value = try await metadata.media(.image, as: SwiftUI.Image.self) // `value` is a `SwiftUI.Image?`