Core Transferable

RSS for tag

Declare a transfer representation for your model types to participate in system sharing and data transfer operations.

Posts under Core Transferable tag

12 Posts

Post

Replies

Boosts

Views

Activity

Drag and Drop stopped working after upgrading from macOS 15 to 26
When I drag and drop a file with flag "shouldAttemptToOpenInPlace: true", I was able to access the original file name in macOS 15. After upgrading to macOS 26, I can't access the original file name anymore. Instead, I got some useless file name such as ".com.apple.Foundation.NSItemProvider.gKZ91u.tmp". The app no longer works with these tmp filenames because it needs the orignal file name to do the file transfer. (Btw, this is a WinSCP like app on Mac platform) Could you please check and fix this issue? Thank you. FileRepresentation(contentType: .item, shouldAttemptToOpenInPlace: true)
1
0
182
1d
Core Transferable Error
I'm developing an app that uses the SwiftUI .photosPicker modifier to allow the user to open videos from their photos. While many videos successfully load, one video results in the following errors occurring: Error loading com.apple.quicktime-movie: <decode: bad range for [%@] got [offs:100 len:1229 within:0]> Error loading public.movie: <decode: bad range for [%@] got [offs:87 len:1229 within:0]> "The operation couldn’t be completed. (CoreTransferable.TransferableSupportError error 0.)" I was able to isolate the line of code within the Transferable where this occurs to be the following: try FileManager.default.copyItem(at: received.file, to: destination) Is there something that I can do to ensure the app can reliably open any video? The entire transferable struct is as follows: import Foundation import CoreTransferable import UniformTypeIdentifiers struct Video: Transferable { let url: URL let filename: String static var transferRepresentation: some TransferRepresentation { FileRepresentation(contentType: .mpeg4Movie) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .quickTimeMovie) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .avi) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .mpeg) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .mpeg2Video) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .video) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } FileRepresentation(contentType: .movie) { video in SentTransferredFile(video.url) } importing: { received in try Video.transfer(from: received) } } static func transfer(from received: ReceivedTransferredFile) throws -> Video { let destination = FileManager.default.temporaryDirectory.appendingPathComponent(received.file.lastPathComponent) if FileManager.default.fileExists(atPath: destination.path) { try FileManager.default.removeItem(at: destination) } try FileManager.default.copyItem(at: received.file, to: destination) return Video(url: destination, filename: received.file.lastPathComponent) } }
1
0
151
Jun ’25
dropDestination does not work inside List
I've discovered an issue with using iOS 16's Transferable drag-and-drop APIs for SwiftUI. The dropDestination modifier does not work when applied to a subview of a List. This code below will not work, unless you replace the List with a VStack or any other container (which, of course, removes all list-specific rendering). The draggable modifier will still work and the item will drag, but the dropDestination view won't react to it and neither closure will be called. struct MyView: View { var body: some View { List { Section { Text("drag this title") .font(.largeTitle) .draggable("a title") } Section { Color.pink .frame(width: 400, height: 400) .dropDestination(for: String.self) { receivedTitles, location in true } isTargeted: { print($0) } } } } } Has anyone encountered this bug and perhaps found a workaround?
8
0
3.4k
Apr ’25
Questions about Apple login authorization data behavior during App transfer
After the App transfer is initiated, will the replacement of the old and new certificates affect user authorization? (Based on some replies from DTS on the forum [Apple login authorization data is generated in combination with the team ID to which the App currently belongs], it is speculated that after the App transfer, during the period when the certificate configuration of the new team ID is not completed, authorization or authentication may not be performed normally, resulting in users being unable to use the Apple login function normally) During the 60-day migration period, if the user authorizes or cancels authorization and then authorizes again in the old app, will the authorized data be different? If so, will transfer_sub be included in the authorization operation?
0
0
82
Mar ’25
ShareLink of a movie is inconsistent
In my app, I have a ShareLink that attempts to share a movie. struct MovieTransferable: Transferable { let url: URL let writeMovie: (URL) -&gt; () static var transferRepresentation: some TransferRepresentation { DataRepresentation( exportedContentType: .movie, exporting: { (movie) in // Write the movie into documents. movie.writeMovie(movie.url) return try! Data(contentsOf: movie.url) }) FileRepresentation( exportedContentType: .movie, exporting: { (movie) in // Write the movie into documents. movie.writeMovie(movie.url) return SentTransferredFile(movie.url) }) } } The ShareLink works if you try to share the movie with the Photos app, Air Drop, and iMessage. If I share to WhatsApp, the movie shows up as empty (zero length), but there's a movie. If I share to Discord, the movie is not displayed at all (only the comment). Instagram posts a dialog saying it won't allow movies and to use the app (why are they even in the ShareLink option for movies?). YouTube processes for a bit and then does nothing (no upload). Are there things that I can do to make the Transferable accepted at more of the end points? It's at fps 30 and I've tried most of the available codec's. The size is the same as the iPhone's screen, so the aspect ratio is a bit odd. However, if I go directly to the app (Discord, etc...) upload from my phone works fine. Any help would be appreciated to make this more viable.
2
0
327
Mar ’25
SwiftUI Transformable: support drag to Finder on macOS
I am trying to support dragging out a 'file' object from my app into Finder, on macOS. I have my object conform to Transferable and the files are saved on disk locally, so I just want to pass it the URL. This works fine when dragging out to other apps, like Notes or Mail, but not in Finder. I setup a ProxyRepresentation as well, as suggested by another thread, but it doesn't seem to help. Is there any other setup I need to do in the Xcode project file for it to work, or is there something else that I'm missing? @available(iOSApplicationExtension 17.0, macOSApplicationExtension 14.0, *) extension FileAttachments: Transferable { public static var transferRepresentation: some TransferRepresentation { FileRepresentation(exportedContentType: UTType.content) { content in SentTransferredFile(content.fullFileURL(), allowAccessingOriginalFile: false) } .exportingCondition { file in if let fileUTI = UTType(filenameExtension: file.fullFileURL().pathExtension), let fileURL = file.fullFileURL() { print("FileAttachments: FileRepresentation exportingCondition fileUTI: \(fileUTI) for file: \(fileURL)") return fileUTI.conforms(to: UTType.content) } return false } .suggestedFileName{$0.fileRenamedName} ProxyRepresentation { file in if let fileURL = file.fullFileURL() { print("FileAttachments: ProxyRepresentation returning file") return fileURL } return file.fullFileURL()! } } }
1
0
347
Feb ’25
TransferRepresentation, AppEntities and AppIntents
Hi, I am trying to understand how this mechanism integrates with shortcuts (and i guess siri + apple intelligence in near future) and other apps. Basic setup is an AppEntity that implements 'transferable' and is returning a DataRepresentation of 'text'. got an AppIntent returns a one of the 'entitities' and I'm simply trying to pass the result to initially email or another app using shortcuts. even with canned 'hello world' string being marshalled into DataRepresentation(.text) I am not seeing anything in usual system targets like email, messages, notes. It opens the app ok, but no text is present. (note: if I use an incorrect DataRepresentation type with email it'll flat out fail saying 'not correct 'text' type) What exactly do I need to do here and is there any example code I can look at? thanks
1
0
346
Feb ’25
Validate drag operations with Transferable
Let's say I want to build a simple photo management app on Mac or iPad with Swift UI. This app has multi-window support. My photos are organized inside albums. I should be able to drag photos between windows from one album to another. I struggle to get this working properly with Swift UI. Writing modern code I would like to use Transferable. Let's say my photos are not real files. So I can't use a FileRepresentation. Instead I use CodableRepresentation and encode an identifier. This identifier is later used to drive the move operation between folders. I ran into some limitations here Transferable seems to be meant for copy-like Drag & Drop operations. I have no possible to get a "move" cursor on macOS (it's always the copy cursor with the green + sign). Also the API reads like it is about importing/exporting – not moving. When using dropDestination on ForEach, I completely lack the possibility to deny a drop (e.g. when a photo is already part of the album). I'd like to have modifier key to switch between copying and moving. Sometimes a drop should be redirected to a different index. How to do that? Is there any chance to do this with Transferable? It even doesn't seem to be easy with NSItemProvider and onDrop/onDrag? Or should we still use a plain old UICollectionView/NSCollectionView, if we want to have more sophisticated control over drag/drop validation?
4
0
416
Jan ’25
transferRepresentation for AppEntity containing parameters of multiple types
I have an App Intent that returns a MyEntity value with the following properties: struct MyEntity: AppEntity { @Property(title: "Title") var title: String? @Property(title: "Image") var image: IntentFile? } I created a Shortcut that takes the output value of this intent and passes it as the input to the Send Message action. When I tap the MyEntity parameter in the message action, it shows to be of Type MyEntity. Below that, I can select 1 of 3 options: MyEntity, Title, or Image. When I run the shortcut, a new message compose window appears with the following behavior depending on the selected option: MyEntity - the message draft is empty Title - the message draft shows the title string Image - the message draft shows the image My expected and desired result when MyEntity is selected would be a message draft populated with the image and the title string as text. How would I achieve this? Is it possible? I've experimented with conforming MyEntity to Transferable. That's enabled use cases such as passing the MyEntity input as Type Image for example. Do I need to create a custom UTType to represent MyEntity, or is that unrelated to my issue? I haven't explored this yet but seems potentially related!
0
0
383
Jan ’25
SwiftUI Audio File Export via draggable
Hey everyone, TL;DR How do I enable a draggable TableView to drop Audio Files into Apple Music / Rekordbox / Finder? Intro / skip me I've been dabbling into Swift / SwiftUI for a few weeks now, after roughly a decade of web development. So far I've been able to piece together many things, but this time I'm stuck for hours with no success using Forums / ChatGPT / Perplexity / Trial and Error. The struggle Sometimes the target doesn't accept the dropping at all sometimes the file data is failed to be read when the drop succeeds, then only as a stream in apple music My lack of understanding / where exactly I'm stuck I think the right way is to use UTType.fileUrl but this is not accepted by other applications. I don't understand low-level aspects well enough to do things right. The code I'm just going to dump everything here, it includes failed / commented out attempts and might give you an Idea of what I'm trying to achieve. // // Tracks.swift // Tuna Family // // Created by Jan Wirth on 12/12/24. // import SwiftySandboxFileAccess import Files import SwiftUI import TunaApi struct LegacyTracks: View { @State var tracks: TunaApi.LoadTracksQuery.Data? func fetchData() { print("fetching data") Network.shared.apollo.fetch(query: TunaApi.LoadTracksQuery()) { result in switch result { case .success(let graphQLResult): self.tracks = graphQLResult.data case .failure(let error): print("Failure! Error: \(error)") } } } @State private var selection = Set<String>() var body: some View { Text("Tracks").onAppear{ fetchData() } if let tracks = tracks?.track { Table(of: LoadTracksQuery.Data.Track.self, selection: $selection) { TableColumn("Title", value: \.title) } rows : { ForEach(tracks) { track in TableRow(track) .draggable(track) // .draggable((try? File(path: track.dropped_source?.path ?? "").url) ?? test_audio.url) // This causes a compile-time error // .draggable(test_audio.url) // .draggable(DraggableTrack(url: test_audio.url)) // .itemProvider { // let provider = NSItemProvider() // if let path = self.dropped_source?.path { // if let f = try? File(path: path) { // print("Transferring", f.url) // // // } // } // // provider.register(track) // return provider // } // This does not } } .contextMenu(forSelectionType: String.self) { items in // ... Button("yoooo") {} } primaryAction: { items in print(items) // This is executed when the row is double clicked } } else { Text("Loading") } // } } } //extension Files.File: Transferable { // public static var transferRepresentation: some TransferRepresentation { // FileRepresentation(exportedContentType: .audio) { url in // SentTransferredFile( self.) // } // } //} struct DraggableTrack: Transferable { var url: URL public static var transferRepresentation: some TransferRepresentation { FileRepresentation (exportedContentType: .fileURL) { item in SentTransferredFile(test_audio.url, allowAccessingOriginalFile: true) } // FileRepresentation(contentType: .init(filenameExtension: "m4a")) { // print("file", $0) // print("Transferring fallback", test_audio.url) // return SentTransferredFile(test_audio.url, allowAccessingOriginalFile: true) // } // importing: { received in // // let copy = try Self.(source: received.file) // return Self.init(url: received.file) // } // ProxyRepresentation(exporting: \.url.absoluteString) } } extension LoadTracksQuery.Data.Track: @retroactive Identifiable { } import UniformTypeIdentifiers extension LoadTracksQuery.Data.Track: @retroactive Transferable { // static func getKind() -> UTType { // var kind: UTType = UTType.item // if let path = self.dropped_source?.path { // if let f = try? File(path: path) { // print("Transferring", f.url) // if (f.extension == "m4a") { // kind = UTType.mpeg4Audio // } // if (f.extension == "mp3") { // kind = UTType.mp3 // } // if (f.extension == "flac") { // kind = UTType.flac // } // if (f.extension == "wav") { // kind = UTType.wav // } // // } // } // return kind // } public static var transferRepresentation: some TransferRepresentation { ProxyRepresentation { $0.dropped_source?.path ?? "" } FileRepresentation(exportedContentType: .fileURL) { <#Transferable#> in SentTransferredFile(<#T##file: URL##URL#>, allowAccessingOriginalFile: <#T##Bool#>) } // FileRepresentation(contentType: .fileURL) { // print("file", $0) // if let path = $0.dropped_source?.path { // if let f = try? File(path: path) { // print("Transferring", f.url) // return SentTransferredFile(f.url, allowAccessingOriginalFile: true) // } // } // print("Transferring fallback", test_audio.url) // return SentTransferredFile(test_audio.url, allowAccessingOriginalFile: true) // } // importing: { received in // // let copy = try Self.(source: received.file) // return Self.init(_fieldData: received.file) // } // ProxyRepresentation(exporting: \.title) } }
0
0
426
Dec ’24
Bug with Transferable + AppEntity
Hello all, I'm finding myself with a compile error when trying to use a defined UTType for Transferable conformance when the type is also an AppEntity. The compiler error is Could not determine the identifier of `.todo`. Please use a UTType defined by the UniformTypeIdentifiers framework However, said compiler error only shows up after adding AppEntity conformance. So, in order to reproduce: Create any type, conform to Codable struct Todo: Codable { var id: UUID var title: String var completed: Bool } Create a UTType extension for the new type extension UTType { public static let todo: UTType = UTType(exportedAs: "org.nameghino.types.todo") } Add Transferable conformance extension Todo: Transferable { static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .todo) ProxyRepresentation(exporting: \.title) } } At this point, the code compiles correctly on Xcode 16.2 beta 2 (16C5013f) Add AppEntity conformance extension Todo: AppEntity { static var typeDisplayRepresentation: TypeDisplayRepresentation = "todo_title" static var defaultQuery = Todo.Query() var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(title)") } struct Query: EntityQuery { typealias Entity = Todo init() {} func entities(for identifiers: [UUID]) async throws -> [Todo] { return [] } func suggestedEntities() async throws -> [Entity] { return [] } } } Now the code is not compiling with the aforementioned error.
3
1
616
Dec ’24
Set filename to use for "Save to Files" with ShareLink?
Isn't there no way to set the default filename to use when we want to save a DataRepresentation to a file? If I export to JSON, the filename is "JSON.json" is used by iOS, even if I set the name to use in SharePreview. struct ContentView: View {     let car = Car(id: UUID(), name: "911", items:                     [Item(id: UUID(),date: .now, desc: "oil change"),                      Item(id: UUID(),date: .now, desc: "Battery")])     var body: some View {         VStack {             ShareLink(item: car, preview: SharePreview(car.name))         }         .padding()     } } extension UTType {     static var car: UTType = UTType(exportedAs: "com.acme.cararchive") } struct Car: Codable {     let id: UUID     let name: String     let items: [Item] } extension Car: Transferable {     static var transferRepresentation: some TransferRepresentation {         DataRepresentation(contentType: .json) { archive in             try JSONEncoder().encode(archive)         } importing: { data in             try JSONDecoder().decode(Car.self, from: data)         }     } } struct Item: Codable {     let id: UUID     let date: Date     let desc: String }
4
0
2.6k
Nov ’24