我需要生成一个不会重复的int值(至少在理论上是这样)。我知道有arc4random()fnc,但是我不确定如何在当前日期或日期使用它:(
最佳答案
这将返回一个与MySQL中生成的UUID非常相似的唯一密钥。
+ (NSString *)uuid
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return [(NSString *)uuidStringRef autorelease];
}
ARC版本:
+ (NSString *)uuid
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return (__bridge_transfer NSString *)uuidStringRef;
}
关于iphone - 如何生成唯一标识符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7016311/