Sort NSFetchedResultsController results by user location

Posted by cgp on Stack Overflow See other posts from Stack Overflow or by cgp
Published on 2010-04-19T16:49:53Z Indexed on 2010/04/19 16:53 UTC
Read the original article Hit count: 261

I have an application that contains some Locations in Core Data, and I want to show them to the user in order of proximity to the user's location. I am using an NSFetchedResultsController to serve the locations to the Table View. I thought about creating a virtual accessor method that returns the location's distance from the user, that would be calculated using a "global" CoreLocationManager, but it crashes with reason:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath distanceFromCurrentLocation not found in entity < NSSQLEntity Location id=4>'

I also give the user the option to sort alphabetically, so I would prefer it if I kept the NSFetchedResultsController, if possible.

How should I do it?

Thanks!

© Stack Overflow or respective owner

Related posts about core-data

Related posts about nsfetchedresultscontrolle