• 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: NSString inaccurate Hash
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString inaccurate Hash


  • Subject: Re: NSString inaccurate Hash
  • From: Gregory Weston <email@hidden>
  • Date: Sun, 4 Feb 2007 18:14:01 -0500

d2kagw wrote:

I knew NSString hash wasn't exactly unique, but I would have expected
a little more than this :P

are there any other good hash methods/classes avaliable that I can
use to generate hashes ( my app creates cache files of accessed data
and the hash was meant to be the unique filename for the cache )

If you know they're not guaranteed to be unique then hoping they're "unique enough" to be usable as sibling file names isn't really a sensible plan IMO.


If you want unique, I'd use a UUID.

+ (NSString*)uniqueID
{
CFUUIDRef theRef = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef theString = CFUUIDCreateString(kCFAllocatorDefault, theRef);
NSString* theResult = [NSString stringWithString:(NSString*) theString];
CFRelease(theString);
CFReleast(theRef);
return theResult;
}


Tack on an extension if you like and you should be golden.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: NSString inaccurate Hash
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: Strange window controller behaviour with "move focus to next window..."
  • Next by Date: Re: menu titles change between IB and running the app...
  • Previous by thread: Re: NSString inaccurate Hash
  • Next by thread: Re: NSString inaccurate Hash
  • Index(es):
    • Date
    • Thread