-
StackOverflow 文档
-
iOS 教程
-
UUID(通用唯一标识符)
-
生成 UUID
随机 UUID
迅速
func randomUUID() -> NSString{
return NSUUID.UUID().UUIDString()
}
Objective-C
+ (NSString *)randomUUID {
if(NSClassFromString(@"NSUUID")) { // only available in iOS >= 6.0
return [[NSUUID UUID] UUIDString];
}
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef cfuuid = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
CFRelease(uuidRef);
NSString *uuid = [((__bridge NSString *) cfuuid) copy];
CFRelease(cfuuid);
return uuid;
}