SwiftUI ShareLink doesn't show option "Copy" when sharing text

With a Button I can directly copy contents to the clipboard via UIPasteboard.general.setObjects(objects), but this is iOS-specific so I was hoping that ShareLink would allow me to share items in a platform-independent way. Is it possible to show a Copy item in the ShareLink sheet?

import SwiftUI

struct ContentView: View {
    let myType = MyType()
    
    var body: some View {
        ShareLink(item: myType, preview: SharePreview(myType.text))
    }
}

class MyType: Transferable {
    let text = "asdf"
    
    static var transferRepresentation: some TransferRepresentation {
        ProxyRepresentation { myType in
            return myType.text
        }
    }
    
}

#Preview {
    ContentView()
}
Answered by DTS Engineer in 790613022

Oh, indeed. What I tried was actually below, which works if you would share a piece of text:

ShareLink(item: myType.text) 

Other than that, I suggest that you file a feedback report for the ShareLink folks to investigate.

Currently there is a bug that prevents the Copy action from appearing when the preview argument is provided. Removing the preview argument should work around the issue.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Removing the preview argument should work around the issue.

That's not possible, that argument is required when sharing an instance of Transferable.

Accepted Answer

Oh, indeed. What I tried was actually below, which works if you would share a piece of text:

ShareLink(item: myType.text) 

Other than that, I suggest that you file a feedback report for the ShareLink folks to investigate.

SwiftUI ShareLink doesn't show option "Copy" when sharing text
 
 
Q