NSPredicate between float values ​​(latitude and longitude) from CoreData

I have a CoreData object containing latitude and longitude coordinates. I just want to set NSPredicate to get records between specific coordinates. 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 BETWEENfrom NSArraywith objects [NSNumber numberWithFloat:]and got a failure with the exception NSCFNumbercontstantValue unrecognized selector sent to the instance

Any suggestions would be highly appreciated.

+4
source share
1 answer

Change your code to

NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"lat <= %f AND lat >= %f AND lon <= %f AND lon >= %f",
maxLat, minLat, maxLon, minLon];
+5
source

Source: https://habr.com/ru/post/1535972/


All Articles