【发布时间】:2016-06-20 23:22:52
【问题描述】:
我一直在浏览许多论坛和教程,希望能够加快我的 cloudkit 应用程序的速度——(至少)答案似乎归结为将服务质量功能设置为“UserInteractive”。目前,用 3 条记录更新一个表控制器大约需要 2/3 秒,每条记录只有一个字符串变量,通过标签显示。据我所知,将 qos 设置为用户交互将迫使 UI 更新得更快。但是,我不确定如何完整地正确实现 qos 代码。就目前而言,这是我的代码,需要 2/3 秒才能加载。
func fetch()
{
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Dining", predicate: predicate)
publicDatabase.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
if (error != nil)
{
print("Error" + (error?.localizedDescription)!)
}
else
{
for result in results!
{
self.categories.append(result)
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
}
}
}
fetch()
}
因此,为了获得更快的 UI 响应,我可以实现这样的功能吗?
func fetch()
{
let publicDatabase = CKContainer.defaultContainer().publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Dining", predicate: predicate)
publicDatabase.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
if (error != nil)
{
print("Error" + (error?.localizedDescription)!)
}
else
{
for result in results!
{
self.categories.append(result)
}
let qualityOfServiceClass = QOS_CLASS_UserInteractive
let Queue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(Queue, {
print("This is run on the background queue")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
})
}
}
}
fetch()
}
【问题讨论】:
标签: swift uitableview cloudkit nsoperationqueue