gpt4 book ai didi

ios - 如何使用查询在 swift 中获取 cloudkit 数据

转载 作者:搜寻专家 更新时间:2023-11-01 07:21:03 26 4
gpt4 key购买 nike

我试图将所有用户的位置存储在 cloudkit 中,然后由每台设备下载。我在 storeLocation 中的代码上标记了错误:

"Cannot convert value of type '(NSError?, [CKRecord]?)' (aka '(Optional, Optional>)') to expected argument type '(error: NSError?, records: [CKRecord]?) -> Void'"

//saves location in cloud kit //currently works well:

var locArray = [CKRecord]()
func storeLocation(location:CLLocation) {
let locationRecord = CKRecord(recordType: "location")
locationRecord.setObject(location, forKey: "location")
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(locationRecord) { (records, error) in
if error != nil {
print("error saving locations: \(error)")
} else {
print("Locations saved: \(records)")
loadLocation((error, self.locArray)) //where I get error******
}
}
}

//fetches location from cloud kit:

func loadLocation(completion: (error:NSError?, records:[CKRecord]?) -> Void)
{
let query = CKQuery(recordType: "Location", predicate: NSPredicate(value: true))
CKContainer.defaultContainer().publicCloudDatabase.performQuery(query, inZoneWithID: nil){
(records, error) in
if error != nil {
print("error fetching locations")
completion(error: error, records: nil)
} else {
print("found locations: \(records)")
completion(error: nil, records: records)
}
}
}

最佳答案

我相信而不是:

loadLocation((error, self.locArray))

你需要这样调用:

loadLocation() { (error, records) in
// do something here with the returned data.
}

关于ios - 如何使用查询在 swift 中获取 cloudkit 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39004017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com