History
Loading...
Loading...
September 18, 2025
ShareLink with custom preview representations to control how your shared content appears in the system share sheet. Add .sharePreview() modifier to customize the thumbnail and title that users see before sharing.This approach creates a custom `Transferable` type that defines exactly how your content should be shared across different apps, with both structured data export and fallback text representation.
struct Recipe: Transferable {
let title: String
let ingredients: [String]
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .recipe)
ProxyRepresentation(exporting: \.title)
}
}
struct RecipeView: View {
let recipe = Recipe(title: "Pasta", ingredients: ["Noodles", "Sauce"])
var body: some View {
VStack {
Text(recipe.title)
ShareLink(item: recipe) {
Label("Share Recipe", systemImage: "square.and.arrow.up")
}
.sharePreview(recipe.title,
image: Image("recipe-thumbnail"))
}
}
}
extension UTType {
static let recipe = UTType(exportedAs: "com.app.recipe")
}By implementing `Transferable`, you ensure type safety, provide multiple sharing formats for different receiving apps, and maintain control over your data structure while leveraging the system's native sharing capabilities.