Change your code to
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"lat <= %f AND lat >= %f AND lon <= %f AND lon >= %f",
maxLat, minLat, maxLon, minLon];
문제
I have a CoreData Entity containing latitude and longitude coordinates. Just want to set a NSPredicate to get records between certain coordintes. This is what I got so far:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"lat <= %f AND lat >= %f AND lon <= %f AND lon >= %f",minLat,maxLat,minLon,maxLon];
This predicate returns no result at all. Then I tried to search with BETWEEN
condition from NSArray
with [NSNumber numberWithFloat:]
objects and got a crash with exception NSCFNumber
contstantValue unrecognized selector sent to instance
Any suggestions would be much appreciated.
해결책
Change your code to
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"lat <= %f AND lat >= %f AND lon <= %f AND lon >= %f",
maxLat, minLat, maxLon, minLon];