2016-06-12 35 views
1

我有一个recordtype - “DiningTypes”。 “DiningTypes只有一个字段类型,它是一个字符串,我有5条记录......加载一个表需要3-4秒,这是如此缓慢吗?我是否需要在以前的控制器具有更快的UI响应时间?CloudKit - 获取一个字段类型的5条记录...需要3-4秒。为什么这么慢?

import UIKit 
import CloudKit 

class table1: UITableViewController { 

var categories: Array<CKRecord> = [] 
var fetchedcategories: Array<CKRecord> = [] 

override func viewDidLoad() { 
    super.viewDidLoad() 
    func fetchdiningtypes() 

    { 
     let container = CKContainer.defaultContainer() 
     let publicDatabase = container.publicCloudDatabase 
     let predicate = NSPredicate(value: true) 

     let query = CKQuery(recordType: "DiningTypes", 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) 
       } 

           } 
     } 

    } 
    fetchdiningtypes() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return categories.count 
} 
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("dining")  as! table1cell 
    let restaurant: CKRecord = categories[indexPath.row] 
    cell.Name.text = restaurant.valueForKey("Name") as? String 

    return cell 
} 
} 
+0

心中已经频繁^ h如果你的代码尽可能高效,而不是你不能做的更多,那么评论的开发速度比生产慢得多。 – user3069232

+0

您是否在任何在线出版物中看到过此内容?听起来很有希望。 –

回答

1

服务为CloudKit操作的默认质量为NSQualityOfServiceUtility。如果你的应用程序不是在前台当请求运行您可能会看到操作比平常更长的时间来运行。

使用CKQueryOperation并设置其qualityOfServiceNSOperationQualityOfServiceUserInitiated尝试。

+0

关于deylayed响应的道歉,你会碰巧知道任何NSO服务质量启动教程? –

相关问题