如何加速我的Cloudkit查询速度

时间:2016-05-17 22:31:07

标签: ios swift cloudkit

我正在使用Cloudkit创建一个应用程序,允许用户收听我的乐队音乐。以下代码可以正常工作,但只需加载30多秒即可加载5首歌曲。如何改进代码以减少加载时间?

        NSOperationQueue.mainQueue().addOperationWithBlock({
        self.pred = NSPredicate(format: "TRUEPREDICATE")
        let query = CKQuery(recordType: "Radio", predicate: NSPredicate(value: true))
        self.queryOperation.qualityOfService = .UserInteractive
        self.queryOperation = CKQueryOperation (query: query)

        self.queryOperation.recordFetchedBlock = {
            record in

            self.songTitle = record.objectForKey("Titles") as! [NSString]
            self.song = record.objectForKey("Songs") as! [NSURL]

            self.songArray.appendContentsOf(self.song)
            self.songTitleArray.appendContentsOf(self.songTitle)

        }
        self.queryOperation.queryCompletionBlock = {
            queryCursor, error in
            if error != nil {
                dispatch_async(dispatch_get_main_queue()){
                    print("\(error)")
                }
            }          
            else {
                dispatch_async(dispatch_get_main_queue()){
                    self.updateViews()
                }
            }
        }
        self.publicDB.addOperation(self.queryOperation)
        })

0 个答案:

没有答案