How to set the filename of Transferable according to each instance?

It seems that the modifier func suggestedFileName(_ fileName: String) -> some TransferRepresentation can only set the filename for the entire Transferable type.

What I want is to set the filename for each instance.

Every instance of a Transferable type shouldn't have the same filename.

static var transferRepresentation: some TransferRepresentation {
    FileRepresentation(exportedContentType: .myType) { myTransferable in
        let url = try await myTransferable.exportedFileUrl()

        return SentTransferredFile(url) /* maybe set the specific filename on SentTransferredFile? */
     }
    .suggestedFileName("Unnamed")  // maybe this should be a fallback filename
}

Replies

.suggestedFileName { $0.title + ".txt" }

  • How does one use this new iOS17 function when still targeting an older iOS version? TransferRepresentationBuilder does not support control flow statements so I cannot resort to the usual #available(iOS 17, *)

Add a Comment