Re: Localized sorting of a Core Data entity
Re: Localized sorting of a Core Data entity
- Subject: Re: Localized sorting of a Core Data entity
- From: Quincey Morris <email@hidden>
- Date: Thu, 07 Apr 2011 02:13:34 -0700
On Apr 7, 2011, at 01:09, Ray wrote:
> 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...
It should be fairly simple to do with a derived property that you can use in the sort descriptor:
+ (NSSet*) keyPathsForValuesAffectingLocalizedName
{
return [NSSet setWithObject: @"name"];
}
- (NSString*) localizedName
{
return NSLocalizedString (self.name, nil);
}
Of course, if you don't currently have a custom subclass for the entity you'll have to create one. Also, I don't really recommend calling the property "localizedName" -- it's too generic and too likely to get confused with something in the frameworks. (For that matter, I don't recommend calling any property "name". One horrendous debugging experience with exceptions complaining about property name -- where you can't figure out whether it means a property name, or the property named "name", or one of many "name" properties you defined in lots of different classes -- is enough to put an end to that practice.)
_______________________________________________
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