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

[C/C++]代码

– (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;
}

http://www.ctolive.com/space-1023-do-blog-id-2103.html

- (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;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图