public
Last active

A method that returns a UUID in an ARC environment.

  • Download Gist
uuidgen.m
Objective-C
1 2 3 4 5 6 7 8 9
- (NSString *)uuidString {
// Returns a UUID
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFRelease(uuid);
return uuidStr;
}

This is a snippet that returns a UUID in an ARC compatible way.

This implementation is a method that you can drop into a class - if you like you can rewrite it as a class method in an NSString category

For methods that only require uniqueness across a network, eg, filenames for dynamically created resources in an app, - something simpler like [[NSProcessInfo processInfo] globallyUniqueString] might suit.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.