我正在尝试使用ZipFoundation库在macOS应用程序中解压一些归档文件。文件位于桌面上,我已确认路径正确且文件存在。
我有这样的代码:
let fileManager = FileManager()
let sourceURL = URL(fileURLWithPath: monetizeZiPFile.absoluteString)
var destinationURL = URL(fileURLWithPath: dirBuildURL.absoluteString)
destinationURL.appendPathComponent("directory")
do {
try fileManager.createDirectory(at: destinationURL, withIntermediateDirectories: true, attributes: nil)
try fileManager.unzipItem(at: monetizeZiPFile, to: dirBuildURL)
} catch {
print("Extraction of ZIP archive failed with error:\(error)")
}对于unzipItem方法,我收到以下错误:
CFURLResourceIsReachable failed because it was passed an URL which has no scheme
Extraction of ZIP archive failed with error:Error Domain=NSCocoaErrorDomain Code=260
"The file “00-monetize.zip” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/xxxxxxxx/Desktop/Componize-Builds/DOC-8621/Monetize/00-monetize.zip}我必须在项目目录中才能让ZipFoundation工作吗?
发布于 2021-02-23 11:57:52
对于路径,请使用path,而不要使用absoluteString。
https://stackoverflow.com/questions/62701689
复制相似问题