I'm developing an app that allows you to search for items and sort by distance from a given point. The approach I'm using is that when I ingest the data from the remote API, I calculate the distance from my current location and store that as an attribute of the CoreData managed object. This works perfectly well when I'm sitting there developing at home, but when I use on the device, then move the device to a different location, the attributes are then incorrect since the distance has now changed for all elements.
The approach I'm considering is to run through the entire core data store and update the distance attribute when the iPhone changes location.
The obvious problem is that I can't do this for every single movement since I'd be running through the full CoreData store every time the user moves an inch. This would kill the battery and cause a slow user experience
Some solutions:
While these solutions should probably work, I imagine that there must be a more elegant solution.
Has anyone solved a similar issue to this?
As you probably know, you can configure CLLocationManager using distanceFilter and desiredAccuracy. This covers item 2.
100 items will not stress core data at all, unless they are gigantic items.
And you should always try to do non-UI things in the background.
So, I think you've got it covered; there's nothing inelegant about this approach.
Try it and see what, if any, performance problems you get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With