I found the BSFetchedResultsController github project , which is a subclass of NSFetchResultsController, which does what Martin suggested in that it sorts in memory using an arbitrary sort descriptor, in addition, it also registers changes in context and again calculates any index changes taking into account arbitrary sort descriptor. All in all a very impressive feat! I have successfully used it to sort by distance as follows:
BSFetchedResultsController* fetchedResultsController = [[BSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
Since it has an old project, it does not have ARC, so when you include two files, do not forget to mark .m with the -fno-objc-arc compiler flags in Target, Build Phases. Also keep in mind that the developer believes that the code is not ready for production, so be sure to use the appropriate tests if you use it.
In my code above, I have a temporary coreLocation property on my subclass of the managed entity object, you can see how to achieve this here . In addition, calculating distances is inefficient; you may need to cache the distance in the object, rather than recount it with each comparison.
Finally, it seems that this project arose because the creator of Daniel Thorpe Stackoverflow's question remained unanswered, forcing him to solve the problem and post the only answer himself, so I think that if you find his project useful, you could kindly vote for his post like me.
malhal
source share