您的位置:首页 > 移动开发 > Objective-C

iOS开发技巧:使用Objective-C创建UUID的代码

2011-11-29 20:57 681 查看
- (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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: