我的completionHandler在performQuery中被跳过了。
let container = CKContainer.defaultContainer()
var publicDB: CKDatabase!
publicDB = container.publicCloudDatabase
let query = CKQuery(recordType: "Centers", predicate: NSPredicate(value: true))
publicDB.performQuery(query, inZoneWithID: nil, completionHandler: { results, error in
if error != nil
{
dispatch_async(dispatch_get_main_queue())
{
println("error loading: \(error)")
}
}
else
{
self.centerResults = results
}
})
var center = Center()
for item in centerResults当我到达"for“语句的底部时,centerResults是零。我的意图是阅读我的公共“中心”模式中的所有条目。
在我的仪表板中,我有一个“中心”模式,包含4个公共记录。
有什么不对的?
发布于 2015-08-26 13:34:10
performQuery是一个异步调用。因此,在调用completionHandler之前,您可能会到达for循环。尝试将代码从底部移动到completionHandler内部。并在completionHandler的第一行上设置一个调试,以查看发生了什么。
https://stackoverflow.com/questions/32227924
复制相似问题