CKError: Query filter exceeds the limit of values: 250 for container
You're requesting more CKRecords to iCloud before your query operation finished.
...
operation.queryCompletionBlock = {
(cursor, error) in
if let error = error {
//handle error
} else if let cursor = cursor {
self.fetchVisits(cursor)
} else {
//all done!
}
}
...
Function self.fetchVisits(cursor)
call is done inside the completion block, this means that your are requesting for more records before your current operation has finished.
Possible solution is to use a closure (completionHandler) in which you include the CKQueryCursor, when user need more records (scroll a table or whatever) you call one again self.fetchVisits
passing the cursos received on your closure.
Ok, so I've seen this before and the issue is, I believe, a bug in on the CloudKit servers. In my experience, it has to do with complex queries.
If you try changing your predicate to:
NSPredicate(value: true)
Or even simplifying your existing one by removing the ANY part, that may be enough to fix it.