• 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
Re: Need localization-proof method of transporting dates.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need localization-proof method of transporting dates.


  • Subject: Re: Need localization-proof method of transporting dates.
  • From: Michael Ash <email@hidden>
  • Date: Wed, 8 Apr 2009 10:10:46 -0400

On Wed, Apr 8, 2009 at 7:46 AM, Graham Cox <email@hidden> wrote:
>
> On 08/04/2009, at 2:45 PM, Graham Cox wrote:
>
>> Thanks for all your help - just remains to be seen now if certain users
>> can now open my app! ;)
>
> It occurs to me that there is another potential problem that I've
> overlooked. System locale affects sorting, right? At least the comment in
> the System Preferences > International suggests that to be the case, and it
> makes sense of course.
>
> So when I hash a dictionary, I sort the keys to ensure a consistent order
> for the items, but if the sorting can vary with locale, I'm going to be
> stuffed. Is there a locale-proof way to sort the keys?

The compare: method is not localized, so you're fine.

> The current code is:
>
> @implementation NSDictionary (GCHash)
>
> - (NSData*)             gc_hash
> {
>        NSMutableData*  data = [NSMutableData data];
>        NSMutableArray* keys = [[self allKeys] mutableCopy];
>
>        [keys sortUsingSelector:@selector(caseInsensitiveCompare:)];    //
> <<----------- potential problem????

Well, yes, but just because caseInsensitiveCompare: is going to
compare unequal strings as being the same, so if your dictionary
contains two keys which differ only by case, they won't be sorted into
any particular order. Since you care about the sort order only to get
consistent results between runs and not for presentation or anything
of the like, just use compare:.

Mike
_______________________________________________

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

References: 
 >Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Christopher Kane <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Michael Ash <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Michael Ash <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Storing bundle loaded main class instances in NSArray
  • Next by Date: Re: NSTask & Quitting Processes ...
  • Previous by thread: Re: Need localization-proof method of transporting dates.
  • Next by thread: Re: Need localization-proof method of transporting dates.
  • Index(es):
    • Date
    • Thread