我尝试了许多不同的方法来获取记录并检查了 stackoverflow 上的相同问题,但不能获取超过 100 条记录。
之前,我使用 CKQuery 而不是 CKQueryOperation 来使用resultsLimit
参数。
这是我的代码:
func initData(){
// show activity indicator
self.activityIndicatorView.hidden = false
// hide connection error button
self.connectionErrorButton.hidden = true
let container = CKContainer.defaultContainer()
let publicDB = container.publicCloudDatabase
let predicate = NSPredicate(value: true)
let sort = NSSortDescriptor(key: "id", ascending: true)
var newInfo = Array<CKRecord>()
let query = CKQuery(recordType: "info", predicate: predicate)
query.sortDescriptors = [sort]
let queryOperation = CKQueryOperation(query: query)
queryOperation.queuePriority = .VeryHigh
queryOperation.resultsLimit = 150;
// Fetch the pokemons for the record
func fetched(record: CKRecord!) {
newInfo.append(record)
}
queryOperation.recordFetchedBlock = fetched
queryOperation.queryCompletionBlock = { [unowned self] (cursor, error) in
if (error != nil) {
dispatch_async(dispatch_get_main_queue()) {
self.connectionErrorButton.hidden = false
self.activityIndicatorView.hidden = true
return
}
} else {
dispatch_async(dispatch_get_main_queue()) {
self.infos.removeAll()
self.infos = newInfo
self.tableView.reloadData()
self.activityIndicatorView.hidden = true
return
}
}
}
publicDB.addOperation(queryOperation)
}