First make sure that Core Data is a hierarchy of objects in the first place. So you are not querying for columns, you're querying for objects.
With this, you need to build NSFetchRequest with NSPredicate , and the predicate will be something like strings:
[NSPredicate predicate withFormat:@"latitude > %@ AND latitude < %@ AND longitude > %@ and longitude < %@", someFloatObject1, someFloatObject2, someFloatObject3, someFloatObject4];
You can also add sorting to NSFetchRequest , although you cannot perform calculations in sorting. Therefore, you can sort after the objects are retrieved.
Update
You may have a transient property on your objects, and then there is a method that says something like "-updateDistanceCalFrom: someFloat". Then using an array of objects you can do the following:
NSArray *myFetchedArray = ... [myFetchedArray makeObjectsPerformSelector:@(updateDistanceCalcFrom:) withObject:someFloatObject]; NSSortDescriptor *calcSort = ...; NSArray *descriptors = [NSArray arrayWithObject:calcSort]; [calcSort release], calcSort = nil; NSArray *sortedArray = [myFetchedArray sortedArrayUsingDescriptors:descriptors];
source share