containsMedia(_:exportableAs:)
Determines if a specific Transferable type can be loaded for an attachment in the metadata.
Declaration
nonisolated func containsMedia(_ attachment: LinkMetadata.Attachment, exportableAs type: (some Transferable).Type) -> BoolParameters
- attachment:
The kind of attachment to test, such as
.image,.icon, and.video. - type:
The
Transferabletype of the media data to test.
Return Value
true if the metadata contains the specified attachment and the attachment’s content type is compatible with the media type.
Discussion
Use this function to immediately determine if metadata has some specific kind of media that can be coerced into a given type:
if metadata.containsMedia(.image, exportableAs: SwiftUI.Image.self) {
// Load the image, and while waiting, display some loading indicator.
} else {
// The metadata contains no image, so omit any UI for it.
}