I am trying to share a custom struct between two users within the App via ShareLink (UIActivityViewController) in SwiftUI. I created a custom Document Type, the Exported Type Identifier and marked the struct as Transferable.
However, while I am able to save the example to a file, I would like to send it to another user via AirDrop or similar, s.t. the App appears as an Application Activity.
import SwiftUI
import UniformTypeIdentifiers
struct SwiftUIView: View {
@State private var customStruct: CustomStruct = CustomStruct()
var body: some View {
ShareLink(item: customStruct, preview: SharePreview(customStruct.name))
}
}
struct CustomStruct: Codable {
var name: String = "Test Example"
var description: String = "Test"
}
extension CustomStruct: Transferable {
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .customStruct)
}
}
extension UTType {
static var customStruct: UTType { UTType(exportedAs: "com.TestExample.CustomStruct") }
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}