英文:
iCloud file download status using ubiquitousItemDownloadingStatusKey not working
问题
如果尝试使用 resourceValues(forKeys:)
检查 URL 的下载状态,您的代码如下:
if let status = try? url.resourceValues(forKeys: [URLResourceKey.ubiquitousItemDownloadingStatusKey]) {
if status.ubiquitousItemDownloadingStatusKey == .current {
print("File download complete.")
}
}
这段代码之前可以正常工作,但现在 Xcode 报错:“Value of type 'URLResourceValues' has no member 'ubiquitousItemDownloadingStatusKey'”,并且我只能从 status
中获取一些 thumbnailDictionary
。有人可以告诉我这里发生了什么吗?我是否犯了一些愚蠢的错误?
英文:
I am trying to check the download status of my url using resourceValues(forKeys:). This is my code
if let status = try? url.resourceValues(forKeys: [URLResourceKey.ubiquitousItemDownloadingStatusKey]) {
if status.ubiquitousItemDownloadingStatusKey == .current {
print("File download complete.")
}
}
This code worked before but now Xcode says "Value of type 'URLResourceValues' has no member 'ubiquitousItemDownloadingStatusKey'" and all I am able to get from status is some thumbnailDictionary. Can anyone tell me what is happening here? Am I making some silly mistake ?
答案1
得分: 1
你在URLResourceValues
上使用了错误的属性:
if let values = try? url.resourceValues(forKeys: [.ubiquitousItemDownloadingStatusKey]),
let status = values.ubiquitousItemDownloadingStatus {
if status == .current {
print("文件下载完成。")
}
}
英文:
You're using the wrong property on URLResourceValues
:
if let values = try? url.resourceValues(forKeys: [.ubiquitousItemDownloadingStatusKey]),
let status = values.ubiquitousItemDownloadingStatus {
if status == .current {
print("File download complete.")
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论