1
votes

I have an NSSet of MKAnnotations obtained by:

NSSet *locationSet = [map annotationsInMapRect:map.visibleMapRect];

And then I write a NSPredicate to pass the desired latitude and longitude like this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"coordinate.latitude == %f AND coordinate.longitude == %f", coord.latitude, coord.longitude];

Now I try to get the desired object by filtering the set:

NSSet *filtered = [locationSet filteredSetUsingPredicate:predicate];
MKAnnotationSubClass *mark = [[filtered allObjects] lastObject];

But get an error saying that my object have not the key I passed:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key latitude.'`

What is the right way to filter this NSSet of annotations using latitude and longitude arguments?

1

1 Answers

2
votes

CLLocationCoordinate2D is not key value coding-compliant, so you can't use the [NSPredicate predicateWithFormat:] method on this object (for filtering by its properties).

Use [NSPredicate predicateWithBlock:] instead and you'll get the same result.