Erva
Erva

Reputation: 47

CloudKit CKQueryOperation doesn't get all records

In CloudKit RecordType is more than 100 records. Following code gets from these only 11 and they are not first 11 records, they are picked randomly from beginning, center and at the end of records. I can't get whats wrong in code.

EDIT : I got it working by changing .reseltsLimit to 5000!

let cloudContainer = CKContainer.default()
        let publicDatabase = cloudContainer.publicCloudDatabase
        let predicate = NSPredicate(value: true)
        let query = CKQuery(recordType: "Sijainti", predicate: predicate)

        var queryOperation = CKQueryOperation(query: query)
        queryOperation.queuePriority = .veryHigh
        queryOperation.resultsLimit = 50
        queryOperation.desiredKeys = ["Koordinaatit"]

        queryOperation.recordFetchedBlock = { (record) -> Void in
            self.sijainnitArray.append(record)
        }

        queryOperation.queryCompletionBlock = { (cursor, error) -> Void in

            if error != nil {
                print("Failed to get data")
                return
            }

            if cursor != nil {
                let newQueryOperation = CKQueryOperation(cursor: cursor!)
                newQueryOperation.cursor = cursor
                newQueryOperation.resultsLimit = queryOperation.resultsLimit
                newQueryOperation.queryCompletionBlock = queryOperation.queryCompletionBlock

                queryOperation = newQueryOperation

                publicDatabase.add(queryOperation)
                return

            }
        }

        publicDatabase.add(queryOperation)

Upvotes: 3

Views: 637

Answers (0)

Related Questions