Reviewing the Apple Developer documentation I found the CFUUID object is available on the iPhone OS 2.0 and later.
Here is the simple code I am using, compliant with ARC.
+(NSString *)getUUID
{
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
NSString * uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
CFRelease(newUniqueId);
return uuidString;
}
I've uploaded my simple but fast implementation of a Guid class for ObjC here: obj-c GUID
Guid* guid = [Guid randomGuid];
NSLog("%@", guid.description);
It can parse to and from various string formats as well.
Reviewing the Apple Developer documentation I found the CFUUID object is available on the iPhone OS 2.0 and later.
Reviewing the Apple Developer documentation I found the CFUUID object is available on the iPhone OS 2.0 and later.
In iOS 6 you can easily use:
NSUUID *UUID = [NSUUID UUID];
NSString* stringUUID = [UUID UUIDString];
More details in Apple's Documentations
In Swift 3.0
var uuid = UUID().uuidString
In Swift 3.0
var uuid = UUID().uuidString
Here is the simple code I am using, compliant with ARC.
+(NSString *)getUUID
{
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
NSString * uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
CFRelease(newUniqueId);
return uuidString;
}
In iOS 6 you can easily use:
NSUUID *UUID = [NSUUID UUID];
NSString* stringUUID = [UUID UUIDString];
More details in Apple's Documentations
The simplest technique is to use NSString *uuid = [[NSProcessInfo processInfo] globallyUniqueString]
. See the NSProcessInfo class reference.
In Swift:
var uuid: String = NSUUID().UUIDString
println("uuid: \(uuid)")
I've uploaded my simple but fast implementation of a Guid class for ObjC here: obj-c GUID
Guid* guid = [Guid randomGuid];
NSLog("%@", guid.description);
It can parse to and from various string formats as well.
The simplest technique is to use NSString *uuid = [[NSProcessInfo processInfo] globallyUniqueString]
. See the NSProcessInfo class reference.
Source: Stackoverflow.com