2
votes

I am trying to write a predicate using coordinates stored in a CloudKit database. I am struggling to find any accurate documentation on the way to format it. Here is what I've come up with:

NSPredicate(format: "distanceToLocation:fromLocation: (%K,%@) < 1000", "locationcoordinates")

I am getting the following error:

Terminating app due to uncaught exception 'CKException', reason: 'Expected CLLocation argument for distanceToLocation:fromLocation:'

Can anyone help me correct this predicate? I'm not sure what argument I need to add.

1

1 Answers

2
votes

In your predicate you have 2 parameters. the %K and %@ but are only supplying 1 value.

It should be something like

    var location:CLLocation = CLLocation(latitude: 0, longitude: 0)
    var radiusInKilometers:CGFloat = 1000;
    var predicate: NSPredicate = NSPredicate(format: "distanceToLocation:fromLocation:(location, %@) < %f", location, radiusInKilometers)!