Re: NSString inaccurate Hash
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