3

Can Anyone let me know what is the difference between creating the Unique Id by these two implementations give below

1)

  CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
    NSString *udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));

2) NSString *guid = [[NSUUID new] UUIDString];

Which one is more reliable as I am working on app from IOS 8 and above.

Abhijeet Kale
  • 1,656
  • 1
  • 16
  • 34
codelover
  • 1,113
  • 10
  • 28

3 Answers3

2

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.

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58
1

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

CFUUIDRef is a Core Foundation function. If your app targets iOS 5 or earlier, you should go with this.

So, for iOS 8 and above, you should use NSUUID for the sake of simplicity and convenience.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
1

Very simple

1.If your app targets iOS 5 or below iOS 5,it belongs to CoreFoundation also you need to set

CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *UUID = CFUUIDCreateString(NULL, uuid);

2.If you app targets iOS6 or above iOS 6,it belongs to Foundation also you need to set

NSString *UUID = [[NSUUID UUID] UUIDString];
user3182143
  • 9,459
  • 3
  • 32
  • 39