Skip to content

Instantly share code, notes, and snippets.

@Abizern
Created December 20, 2011 11:51
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Abizern/1501325 to your computer and use it in GitHub Desktop.
Save Abizern/1501325 to your computer and use it in GitHub Desktop.
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);
CFRelease(uuid);
return uuidStr;
}
@Abizern
Copy link
Author

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