문제

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top