<!--
{
  "availability" : [
    "iOS: 26.4.0 -",
    "iPadOS: 26.4.0 -",
    "macCatalyst: 26.4.0 -",
    "macOS: 26.4.0 -",
    "tvOS: 26.4.0 -",
    "visionOS: 26.4.0 -",
    "watchOS: 26.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "LinkPresentation",
  "identifier" : "/documentation/LinkPresentation/LinkMetadata/setMedia(_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Link Presentation",
      "LinkPresentation"
    ],
    "preciseIdentifier" : "s:16LinkPresentation0A8MetadataV8setMedia_3foryx_AC10AttachmentVt16CoreTransferable0I0RzlF"
  },
  "title" : "setMedia(_:for:)"
}
-->

# setMedia(_:for:)

Sets the media data in the metadata for an attachment.

```
nonisolated mutating func setMedia(_ media: some Transferable, for attachment: LinkMetadata.Attachment)
```

## Parameters

`media`

The value to use for the media that corresponds to the specified attachment.

`attachment`

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

## Discussion

For example, a custom image can be set on some metadata:

```swift
metadata.setMedia(myImage, for: .image)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)