Cursor in CloudKit does not work. Where is mistake?

I’m trying to make cursor the right way. But it doesn’t work. If I set limit 5, then I can see only 5 records, even I move my finger on the map (I’m using MapKit with CloudKit). If 200 then 200, but have to wait for very long time. I’m sure my cursor is wrong. Who can help me?

func getLocation(completed: @escaping (Result<[AppLocation], Error>) -> Void) {
     let sortDescriptor = NSSortDescriptor(key: AppLocation.kName, ascending: true)
     let query = CKQuery(recordType: RecordType.location, predicate: NSPredicate(value: true))
     query.sortDescriptors = [sortDescriptor]
     let operation = CKQueryOperation(query: query)
     operation.resultsLimit = 5
     operation.query = query
     operation.queuePriority = .veryHigh
     operation.qualityOfService = .userInteractive

     var locations = [AppLocation]()
     
     operation.recordFetchedBlock = { record in
       let location = AppLocation(record: record)
       locations.append(location)
     }

     operation.queryCompletionBlock = { (cursor, error) in
       DispatchQueue.main.async {
         if let error = error {
           completed(.failure(error))
         } else {
           completed(.success(locations))
         }
       }
     }
     CKContainer.default().publicCloudDatabase.add(operation)
}
Answered by matovsky in 698705022

Closed.

I haven't tried CloudKit ever, and just have read the docs. But you get cursor in the closure passed to queryCompletionBlock, but you are not using it to get the remaining result. So it is quite reasonable that If I set limit 5, then I can see only 5 records.

Accepted Answer

Closed.

Cursor in CloudKit does not work. Where is mistake?
 
 
Q