NSFetchedResultsController sections localized sorted

Posted by Gerd on Stack Overflow See other posts from Stack Overflow or by Gerd
Published on 2010-04-30T12:14:00Z Indexed on 2010/04/30 12:17 UTC
Read the original article Hit count: 311

How could I use the NSFetchedResultsController with translated sort key and sectionKeyPath?

Problem: I have ID in the property "type" in the database like typeA, typeB, typeC,... and not the value directly because it should be localized. In English typeA=Bird, typeB=Cat, typeC=Dog in German it would be Vogel, Katze, Hund.

With a NSFetchedResultController with sort key and sectionKeyPath on "type" I receive the order and sections - typeA - typeB - typeC

Next I translate for display and everything is fine in English: - Bird - Cat - Dog

Now I switch to German and receive a wrong sort order - Vogel - Katze - Hund

because it still sorts by typeA, typeB, typeC

So I'm looking for a way to localize the sort for the NSFetchedResultsController.

I tried the transient property approach, but this doesn't work for the sort key because the sort key need to be in the entity.

I have no other idea. But I can't believe that's not possible to use NSFetchedResultsController on a derived attribute required for localization?

There are related discussions like http://stackoverflow.com/questions/1384345/using-custom-sections-with-nsfetchedresultscontroller but the difference is that the custom section names and the sort key have probably the same order. Not in my case and this is the main difference.

At the end I would need a sort order for the necessary NSSortDescriptor on a derived attribute, I guess. This sort order has also to serve for the sectionKeyPath.

Thanks for any hint.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsfetchedresultscontrolle