• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Localized sorting of a Core Data entity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Localized sorting of a Core Data entity


  • Subject: Localized sorting of a Core Data entity
  • From: Ray <email@hidden>
  • Date: Thu, 07 Apr 2011 10:09:17 +0200

Let's say I have a Core Data entity called "TestEntity". It has a property called "name", and I inserted three instances in the managed object, saved, etc. The value "name" for these three instances are "A", "B", and "C" respectively. Now I am going to fetch these managed objects using an instance of NSFetchedResultsController, use a UITableview for rendering, etc. I use a NSSortDescriptor to sort the objects by "name" in the table view, something like:

NSSortDescriptor *sortDescriptor =
[[NSSortDescriptor alloc] initWithKey:"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)];

All works swimmingly, I get a table view which shows A, B, C, sorted correctly.

Now I add a .strings file with a localization for "A", "B", and "C":

"A" = "Z";
"B" = "Y";
"C" = "X";

In my cellForRowAtIndexPath method, I use something like:

...

NSManagedObject *obj = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = NSLocalizedString([obj valueForKey:"name"], nil);

...

When switching to the new language, the sorting in the table view is Z, Y, X, because it is using the original sort order of the "name" values... My question is: what would be a good strategy to have the whole thing sort to X, Y, Z in the table view when using the new language? I can't seem to figure this one out...

Thanks,
- Ray.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Localized sorting of a Core Data entity
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Hot can I get called when my view scrolls?
  • Next by Date: Re: Localized sorting of a Core Data entity
  • Previous by thread: Re: Hot can I get called when my view scrolls?
  • Next by thread: Re: Localized sorting of a Core Data entity
  • Index(es):
    • Date
    • Thread