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)
}