onDrop return value from loadObject
I'm using SwiftUI on macOS, and I am trying to implement dragging & dropping folders. To do this, I'm using the onDrop
api, like this:
.onDrop(of: [UTType.fileURL], isTargeted: nil) { itemProviders in
for provider in itemProviders {
provider.loadObject(ofClass: URL.self) { url, error in
print(url)
}
}
return true
}
However, if there are files in the drop operation, I want to return false to onDrop
to signal that the operation has failed, as this should only accept folders.
The problem is, loadObject
runs asynchronously. So to return a result, I would have to wait for it to complete, using something like a semaphore.
This works, but it seems rather clunky. Is there any better way of achieving this?
from Recent Questions - Stack Overflow https://ift.tt/3zUmcRj
https://ift.tt/eA8V8J
Comments
Post a Comment