Is there a built in function equivalent to .NET\'s
Guid.NewGuid();
in Cocoa?
My desire is to produce a string along the lines of
Some code:
For a string UUID, the following class method should do the trick:
+(NSString*)UUIDString {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
if you really want the bytes (not the string):
+(CFUUIDBytes)UUIDBytes {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(theUUID);
CFRelease(theUUID);
return bytes;
}
where CFUUIDBytes is a struct of the UUID bytes.