I m having some issues here.. I am using the following code to generate the uuid in mine application.
- (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
This code returns a NSString
object back. Now I want to store the generated UUID
as unsigned int
. Any suggestions please how can i do it here. Thanks.
bigserial advantages: Integer sequences occupy only 64 bits while UUIDs are 128, so there's a slight storage saving. There's more space in a UUID, but 64 bits is plenty big enough to never run out of IDs. Integers are more human friendly.
A UUID – that's short for Universally Unique IDentifier, by the way – is a 36-character alphanumeric string that can be used to identify information (such as a table row).
In MySQL, a UUID value is a 128-bit number represented as a utf8 string, and the format in hexadecimal number will be as follows. Here, the first three numbers are generated from the low, middle, and high parts of a timestamp.
In MySQL, you can store UUID values in a compact format ( BINARY ) and display them in human-readable format ( VARCHAR ) with help of the following functions: UUID_TO_BIN.
According to the Wikipedia page, UUIDs are 128 bits long. The largest int value you'll be able to work with is 64 bits. Therefore, I'd says you can't store it in an int because there simply isn't room.
Convert UUID to String using .UUIDString
Take string's .hash
property.
Cast to int.
int numericFormUUID = (int)UUIDString.hash;
Note: collision is possible, as always, with hashing. Two users could end up with the same value here, whereas UUID is guaranteed unique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With