I’m working with a custom exported type in my macOS app when I found that SwiftUI’s ShareLink would not display any options for sharing. Currently, I have a type that conforms to public.data
and public.json
, with a unique identifier and file extension too.
Here’s an image of the empty share sheet.
After searching through the documentation on Uniform Type Identifiers, I found this written about the content type.
For document types, conform to public.content, either directly or by conforming to a type that already conforms to public.content. This conformance allows users to share your type over AirDrop.
This seems to be untrue in my context, so I assume that I have made a mistake.
Here’s my current transferable conformance:
extension Quote: Transferable {
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .quote)
}
}
extension UTType {
// Real type identifier is not com.example, of course
static var quote: UTType { UTType(exportedAs: "com.example.quote") }
}
And declarations of exported type identifiers and document types are here.
This is also what the ShareLink looks like:
ShareLink(
item: Quote(text: "In a galaxy far far away..."),
preview: SharePreview("An intersting quote"),
label: { Image(systemName: "square.and.arrow.up") }
)
Does anyone know why this issue with no share options is occurring with this custom exported type identifier?
Oscar Mann is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.