转自: http://blog.prosight.me/index.php/2010/11/670
UUID是128位的值,它可以保证唯一性。通常,它是由机器本身网卡的MAC地址和当前系统时间来生成的。
UUID是由中划线连接而成的字符串。例如:13222F23-C76A-7781-0C12-0293E3B34398.
下面这个方法可以生成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); // 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; }
本文介绍了一种在Objective-C中生成UUID的方法。UUID是一种128位的数值,由MAC地址和系统时间生成,确保了其唯一性。文章提供了一个Objective-C函数,用于创建UUID,并将其转换为字符串形式。
798

被折叠的 条评论
为什么被折叠?



