Created
April 4, 2021 13:43
-
-
Save steipete/f61bb38ddee07a691bff8a4f681d3486 to your computer and use it in GitHub Desktop.
Accept dropping a file onto SwiftUI (both iOS and macOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MIT License.