title: How to turn CBUUID into string
body: <p>I can't find any official way to get a UUID string back out of a CBUUID. These UUIDs can be 2 or 16 bytes long. </p>
  
  <p>The goal is to store CBUUIDs in a file somewhere as a string, and then resurrect with [CBUUID UUIDWithString:] etc. Here is what I have so far. </p>
  
  <pre><code>// returns a simple 4 byte string for 16bit uuids, 128 bit uuids are in standard 8-4-4-4-12 format
  // the resulting string can be passed into [CBUUID UUIDWithString:]
  +(NSString*)CBUUIDToString:(CBUUID*)cbuuid;
  {
      NSData* data = cbuuid.data;
      if ([data length] == 2)
      {
          const unsigned char *tokenBytes = [data bytes];
          return [NSString stringWithFormat:@"%02x%02x", tokenBytes[0], tokenBytes[1]];
      }
      else if ([data length] == 16)
      {
          NSUUID* nsuuid = [[NSUUID alloc] initWithUUIDBytes:[data bytes]];
          return [nsuuid UUIDString];
      }
  
      return [cbuuid description]; // an error?
  }
  </code></pre>