Post

Replies

Boosts

Views

Activity

Get file path from .onDrop on macOS SwiftUI app
I'm building an app to manage and edit some files. To do that, I want to open the files in place dropping them into a view. I cannot find a way to obtain the file URL after the drop operation. If I constrain the file types to .fileURL, the drop frame doesn't activate. If I use .data, I get the file and not the path, which is what I want. Any way to do this the SwiftUI way? .onDrop(of: [.fileURL], isTargeted: $dragOver) { providers -> Bool in providers.first?.loadDataRepresentation(forTypeIdentifier: "public.file-url", completionHandler: { (data, error) in                             if let data = data {                                 print(data.description)                             }                         })                         return true }
3
0
3.3k
May ’23
Get file path from .onDrop on macOS SwiftUI app
I'm building an app to manage and edit some files. To do that, I want to open the files in place dropping them into a view. I cannot find a way to obtain the file URL after the drop operation. If I constrain the file types to .fileURL, the drop frame doesn't activate. If I use .data, I get the file and not the path, which is what I want. Any way to do this the SwiftUI way? .onDrop(of: [.fileURL], isTargeted: $dragOver) { providers -> Bool in providers.first?.loadDataRepresentation(forTypeIdentifier: "public.file-url", completionHandler: { (data, error) in                             if let data = data {                                 print(data.description)                             }                         })                         return true }
Replies
3
Boosts
0
Views
3.3k
Activity
May ’23