Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A method that returns a UUID in an ARC environment.
- (NSString *)uuidString {
// Returns a UUID
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
return uuidStr;

Abizern commented Dec 20, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment