Shekar
Shekar

Reputation: 250

custom nspredicate to be between two distances

Is there a way to narrow my predicate to be between two distances? Currently, all I can create is a predicate that takes in a singular radius and finds all objects within that radius from the user's current location.

var locationPredicate = NSPredicate(format: "distanceToLocation:fromLocation:(%K, %@) < %f", "Location", location,
                                        1000)

For a visual representation, I would want to grab all objects in the orange part of this drawing, with the center being the user's current location. (I can currently only get yellow AND orange). enter image description here

Upvotes: 0

Views: 141

Answers (1)

Palle
Palle

Reputation: 12129

You should be able to use a BETWEEN statement:

NSPredicate(format: "distanceToLocation:fromLocation:(%K, %@) BETWEEN { %f , %f }", "Location", location, lowerBound, upperBound)

Upvotes: 1

Related Questions