How to turn CBUUID into string

前端 未结 8 1036
太阳男子
太阳男子 2020-12-28 20:11

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.

The goal is to store CBUUIDs in a file somewhere as

8条回答
  •  攒了一身酷
    2020-12-28 20:44

    To all those saying that CBUUID is toll-free bridged with CFUUIDRef, it's not.

    CBUUID * foo = [CBUUID UUIDWithString:CBUUIDCharacteristicExtendedPropertiesString];
    CFStringRef fooBar = CFUUIDCreateString(NULL, (__bridge CFUUIDRef)foo);
    if (![CBUUIDCharacteristicExtendedPropertiesString isEqualToString:(__bridge NSString *)fooBar])
        NSLog(@"fubar!");
    

    It's not crashing but you're getting garbage out. It's probably uniquely identifying garbage, but it can't be round-tripped.

    PS: This didn't work as a comment because SO comments oddly don't allow code formatting.

提交回复
热议问题