Skip to content

Instantly share code, notes, and snippets.

@steipete
Created April 4, 2021 13:43
Show Gist options
  • Save steipete/f61bb38ddee07a691bff8a4f681d3486 to your computer and use it in GitHub Desktop.
Save steipete/f61bb38ddee07a691bff8a4f681d3486 to your computer and use it in GitHub Desktop.
Accept dropping a file onto SwiftUI (both iOS and macOS)
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
if let loadableProvider = providers.first(where: { $0.canLoadObject(ofClass: URL.self) }) {
_ = loadableProvider.loadObject(ofClass: URL.self) { fileURL, _ in
if let fileURL = fileURL, fileURL.pathExtension.lowercased() == "zip" {
self.logger.info("Dropped \(fileURL.path)")
DispatchQueue.main.async {
importer.open(zipArchiveURL: fileURL)
}
}
}
return true
}
return false
}
@Lawris
Copy link

Lawris commented Feb 11, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment