I'm dragging existing files from a SwiftUI List (a search result list in a sandboxed, document-based Mac app), and I want drop targets to receive the actual file URL — the same behavior as AppKit's NSOutlineView with outlineView(_:pasteboardWriterForItem:) returning an NSURL: the Finder copies the file, browsers load it, and text views insert its path.
My current implementation is Transferable-based:
FileRepresentation(exportedContentType: .data) { item in
SentTransferredFile(item.fileURL, allowAccessingOriginalFile: true)
}
.suggestedFileName(\.fileURL.lastPathComponent)
With this, what receivers get is a temporary copy in the app's own container (Caches/com.apple.SwiftUI.Drag-<UUID>/), not the actual file URL — despite allowAccessingOriginalFile: true. Dropping on the Finder or onto an application icon works through the copy, but receivers that interpret the URL itself — a browser window, or a text view that inserts the dropped file's path — see the temporary container path.
Note that the dragged files live inside a folder the user has opened as a document (the app is NSDocument-based), so the app already holds security-scoped access to them.
Alternatives don't help either:
DataRepresentation(exportedContentType: .fileURL)returning the URL bytes of the actual file: the pasteboard data is likewise replaced with the copy's URL, and moreover, drops onto application icons (e.g. Safari in the Dock) are no longer accepted at all.onDragwithNSItemProvider(object: url as NSURL): same substitution.
I've already filed this as FB23578716, with detailed reproduction steps and drag-pasteboard dumps.
My questions:
- Is there any way in current SwiftUI (macOS 26/27 SDK) to put the real file URL of an existing file on the drag pasteboard?
- Is the rewriting to a temporary copy intended behavior (for sandbox safety), or a bug?
- If it's intended, is embedding an AppKit view that calls
beginDraggingSession(with:event:source:)with anNSURLpasteboard writer the recommended workaround for now? It does write the real URL, but making it coexist withList's selection and click handling has proven fragile.
Environment:
- macOS: macOS 27 Beta 2 / Version 26.5.2
- Xcode: Version 27.0 Beta 2
- App Sandbox enabled