当前位置: 动力学知识库 > 问答 > 编程问答 >

Best method to create a Unique id for every time in iPhone?

问题描述:

How to create unique Alphanumeric id from iPhone whenever i required? It must be distinct because it is sharable to all iphone.

网友答案:

I use this code in my Utils class to generate the UUID:

+ (NSString *)newUUID
{
    CFUUIDRef uuid = CFUUIDCreate(NULL);
    CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
    NSString *result = [[NSString alloc] initWithFormat:@"%@", [(NSString *)uuidStr lowercaseString]];
    CFRelease(uuidStr);
    CFRelease(uuid);
    return result;    
}

The method starts with new, so make sure to release the string when you are done with it, or autorelease it.

网友答案:

Take a look at CFUUID. A UUID can be expected to be unique across space and time (give or take a few caveats.)

分享给朋友:
您可能感兴趣的文章:
随机阅读: