Search code examples
iosobjective-cnsuuid

Whats this difference between [[NSUUID new] UUIDString] & CFUUIDRef


What's the difference between creating a UUID by these two implementations give below?

1)

CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
NSString *guid = [[NSUUID new] UUIDString];`

Which one is more reliable? I'm working on an app for iOS 8+.


Solution

  • You can find details on NSHipster's uuid-udid-unique-identifier post.

    In the interest of not posting 'link only' answer here are excerpts form the same article:

    NSUUID was added to Foundation in iOS 6 as a way to easily create UUIDs.

    If your app targets iOS 5 or earlier, however, you have to settle for Core Foundation functions on CFUUIDRef

    To sum up, although both return a valid UUID, go ahead and use NSUUID as its easier.