按最早修改记录

时间:2016-06-28 02:36:47

标签: swift cloudkit ckquery ckqueryoperation

我正在使用CloudKit并尝试通过“modificationDate”来记录记录,但是会从最旧的开始填充我的结果限制。例如,如果我创建了4个记录mon,tues,wed,thurs和我只选择其中两个,我会得到mon,tues记录而不是结婚。下面是我要修复的代码。

func fetchRecentModified() {

   let predicate = NSPredicate(value: true)
   let sort = NSSortDescriptor(key: "votes", ascending: true)
   let query = CKQuery(recordType: "Dog", predicate: predicate)
   query.sortDescriptors = [sort]
   let operation = CKQueryOperation(query: query)
   operation.resultsLimit = recordFetchMax

   operation.recordFetchedBlock = { (record) in
       VoteQueue.sharedInstance.append(record)

   }

   operation.queryCompletionBlock = { (cursor, error) in
       dispatch_async(dispatch_get_main_queue()) {
           if error == nil {
               print("There is no error fetching records \(recordFetchMax)")
               print(VoteQueue.sharedInstance)
               API.shared.flagRecords(VoteQueue.sharedInstance)

           } else {
               print("There was a problem fetching the list of dogs please try again")
               print(error)
           }
       }
   }
   self.database.addOperation(operation)

}

我认为这就像标记NSSortDescriptor升序为假一样简单。但这不起作用(经过更多测试后,我发现这将返回记录,其中所选字段的值为0)。

此外,我尝试了一些不同的谓词比较无济于事。有什么想法吗?我准备好永远放弃CloudKit。

0 个答案:

没有答案