CloudKit predicate

Can someone help me identify what is wrong with my predicate string, please?

query = CKQuery(recordType: RecordType, predicate: NSPredicate(format: "(Lat > "+String(currentPlaceLat - limit)+") AND (Lat < "+String(currentPlaceLat + limit)+") AND (Long > "+String(currentPlaceLong - limit)+") AND (Long < "+String(currentPlaceLong + limit)+")")

This is what it prints during runtime:

(Lat > 39.872) AND (Lat < 49.872) AND (Long > -85.493) AND (Long < -75.493)

I want to filter out the records that are between that latitude and that longitude, but Im sure there is something wrong with my query.

Sorry, I am new to CloudKit.

Answered by leo008 in 712292022

Solved with this:

let predicateString = "Lat BETWEEN {" + String(currentPlaceLat - limit) + ", " + String(currentPlaceLat + limit) + "}" + " && " + "Long BETWEEN {" + String(currentPlaceLong - limit) + ", " + String(currentPlaceLong + limit) + "}"

Yes, I know, but I’m avoiding them because I need more precision and I understand these have a 10km precision. Thanks. I want to implement in the way I described.

Accepted Answer

Solved with this:

let predicateString = "Lat BETWEEN {" + String(currentPlaceLat - limit) + ", " + String(currentPlaceLat + limit) + "}" + " && " + "Long BETWEEN {" + String(currentPlaceLong - limit) + ", " + String(currentPlaceLong + limit) + "}"

CloudKit predicate
 
 
Q