How to store UUID as int

I have some problems here. I am using the following code to generate uuid in my application.

- (NSString *)GetUUID { CFUUIDRef theUUID = CFUUIDCreate(NULL); CFStringRef string = CFUUIDCreateString(NULL, theUUID); CFRelease(theUUID); return [(NSString *)string autorelease]; } 

This code returns an NSString object. Now I want to save the generated UUID as an unsigned int . Any suggestions please, how can I do this here. Thanks.

+4
source share
2 answers

According to the Wikipedia page, UUIDs are 128 bits long. The largest int value you can work with is 64 bits. Therefore, I would say that you cannot store it in int, because there is simply no place.

+7
source

Convert UUID to string using .UUIDString

Take the string .hash property.

Pass to int.

int numericFormUUID = (int)UUIDString.hash;


Note: collision is possible, as always, with hashing. Here, two users can have the same value, while the UUID is guaranteed to be unique.

0
source

All Articles