ios - 无法转换“inout NSNumber”类型的值?到预期的参数类型'AutoreleasingUnsafeMutablePointer' 错误
问题描述
我有这个脚本用于检查 *downloaded 文件iCloud
是否可用。但不幸的是,我Cannot convert value of type 'inout NSNumber?' to expected argument type 'AutoreleasingUnsafeMutablePointer<AnyObject?>'
在某些代码行中遇到了错误。请帮我解决这个问题,因为这是我第一次创建代码来检查下载的文件是否在 icloud 中可用。
请参考下图作为错误示例,下面还有代码供您参考。希望你能帮助我。谢谢你。
//-------------------------------------------------------------------
// ダウンロードできるか判定 Judgment or can be downloaded
//-------------------------------------------------------------------
func downloadFileIfNotAvailable(_ file: URL?) -> Bool {
var isIniCloud: NSNumber? = nil
do {
try (file as NSURL?)?.getResourceValue(&isIniCloud, forKey: .isUbiquitousItemKey)
if try (file as NSURL?)?.getResourceValue(&isIniCloud, forKey: .isUbiquitousItemKey) != nil {
if isIniCloud?.boolValue ?? false {
var isDownloaded: NSNumber? = nil
if try (file as NSURL?)?.getResourceValue(&isDownloaded, forKey: .ubiquitousItemIsDownloadedKey) != nil {
if isDownloaded?.boolValue ?? false {
return true
}
performSelector(inBackground: #selector(startDownLoad(_:)), with: file)
return false
}
}
}
} catch {
}
return true
}
解决方案
看起来您复制并粘贴了一些非常旧的代码。此外,这是 Swift,而不是 Objective-C。不要使用 NSURL 或getResourceValue
. 您的代码应该看起来更像这样:
if let rv = try file?.resourceValues(forKeys: [.isUbiquitousItemKey]) {
if let isInCloud = rv.isUbiquitousItem {
// and so on
}
}
等等; 相同的模式适用于其他键。请注意,两者都没有.ubiquitousItemIsDownloadKey
。你可以压缩这样的东西:
if let rv = try file?.resourceValues(
forKeys: [.isUbiquitousItemKey, .ubiquitousItemDownloadingStatusKey]) {
if let isInCloud = rv.isUbiquitousItem {
if let status = rv.ubiquitousItemDownloadingStatus {
if status == .downloaded {
}
}
}
}
推荐阅读
- c# - 为什么 flowLayoutPanel 控件集合中的所有图片框都显示相同的图像?
- javascript - 在 Node.js 中流式传输响应数据时缺少块
- height - 制表符 - 响应式 - 表格高度
- javascript - 查找子字符串时无法返回数组的长度
- javascript - 分页循环javascript jquery php
- powershell - 比较多维数组中的多个对象
- hibernate - 为什么 Hibernate Criteria 投影返回 Null 对象?
- hyperledger-fabric - HLF 1.2 服务发现是否与 HLF 1.1 对等方一起使用?
- java - 如何从 Firestore Android 查询过去 7 天的数据
- sql - 在 SQL Server 中进行级别并从