How can a SwiftUI drag provide the actual file URL of an existing file on macOS (as NSOutlineView does)?

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.
  • onDrag with NSItemProvider(object: url as NSURL): same substitution.

I've already filed this as FB23578716, with detailed reproduction steps and drag-pasteboard dumps.

My questions:

  1. 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?
  2. Is the rewriting to a temporary copy intended behavior (for sandbox safety), or a bug?
  3. If it's intended, is embedding an AppKit view that calls beginDraggingSession(with:event:source:) with an NSURL pasteboard writer the recommended workaround for now? It does write the real URL, but making it coexist with List'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

Dear 1024jp,

Have you tried setting shouldAllowToOpenInPlace to true? As per the documentation for this initializer:

shouldAllowToOpenInPlace

A Boolean value that indicates whether the receiver can try to gain access to the original item on disk and can edit it. If false, the receiver only has access to a copy of the file made by the system.

Hoping this helps,

Richard Yeh  Developer Technical Support

Have you tried setting shouldAllowToOpenInPlace to true?

Unfortunately, the shouldAllowToOpenInPlace flag doesn’t help solving my issue.

Setting that flag prevents the file from being copied by dragging it in Finder. Also, FileRepresentation doesn’t seem to be involved when passing a file URL to another app such as Safari.

It appears that other representations need to be provided as well.

For example, if I add ProxyRepresentation(exporting: \.fileURL.absoluteString) afterward, I can drop the item onto Safari’s Dock icon. However, dropping it onto Safari’s address bar passes the URL of the sandbox container instead, and dropping it onto Safari’s content view does not interact with the page at all.

struct FolderFindDraggedFile: Transferable, Identifiable {
    
    var fileURL: URL
    
    static var transferRepresentation: some TransferRepresentation {
        
        FileRepresentation(exportedContentType: .data) { item in
            SentTransferredFile(item.fileURL, allowAccessingOriginalFile: true)
        }
        .suggestedFileName(\.fileURL.lastPathComponent)
        
        ProxyRepresentation(exporting: \.fileURL)
    }
}

Dear 1024jp,

Thanks for filing the bug report and including a syslog. Would it be possible for you to repackage your sample code into a small test project that replicates the issue? You can add a link to it in this thread, and in Feedback Assistant as well. Alternatively, you could attach the project. I'll take a look.

Thanks,

Richard Yeh  Developer Technical Support

How can a SwiftUI drag provide the actual file URL of an existing file on macOS (as NSOutlineView does)?
 
 
Q