How to Create a Universally Unique Identifier (UUID) in iOS - Online Free Computer Tutorials.

'Software Development, Games Development, Mobile Development, iOS Development, Android Development, Window Phone Development. Dot Net, Window Services,WCF Services, Web Services, MVC, MySQL, SQL Server and Oracle Tutorials, Articles and their Resources

Sunday, June 17, 2012

How to Create a Universally Unique Identifier (UUID) in iOS

UUID's are 128-bit values which are guaranteed to be unique – typically the value is based on a machines ethernet address combined with the current time since October 15, 1582.

UUID's are string values separated by hyphens, for example, here is how a UUID may look: 14862F23-C76A-2548-2541-0293E3B34398.

The method below creates a UUID and returns a string representation of the same:

Create UUID

- (NSString *)createUUID
{
// Create universally unique identifier (object)
CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
 
// Get the string representation of CFUUID object.
NSString *uuidStr = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject) autorelease];
 
// If needed, here is how to get a representation in bytes, returned as a structure
// typedef struct {
// UInt8 byte0;
// UInt8 byte1;
// ...
// UInt8 byte15;
// } CFUUIDBytes;
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuidObject);
 
CFRelease(uuidObject);
 
return uuidStr;
}

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


No comments:

Post a Comment