Ollie G Ollie G - 2 months ago 26
Swift Question

CKLocationSortDescriptor having no effect

Passing my CloudKit query using the

and it is not having any effect. It is displaying on a tableview and it is meant to be in order of closest to user and the distance ascending.


let location = locationManager.location
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Establishment", predicate: predicate)
let sort = CKLocationSortDescriptor(key: "Location", relativeLocation: location!)

query.sortDescriptors = [CKLocationSortDescriptor(key: "Location", relativeLocation: location!)]



After messing around with this from what I can tell it won't sort anything within 2 km, any closer it will revert to last edited. Any ideas how to make this more accurate as I hoping to do this with accuracy to a metre?


I used a TSI and contacted Apple. As it turns out CKLocationSortDescriptor is only accurate to 10kms, this is not a bug apparently it is actually something that they forgot to add to the documentation. The Cloudkit team are working on improving this but cannot give a time line. If you want to order anything closer than 10km you can't at this time.