Skip to content

Instantly share code, notes, and snippets.

@nschum
Created January 1, 2011 21:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nschum/762038 to your computer and use it in GitHub Desktop.
Save nschum/762038 to your computer and use it in GitHub Desktop.
UUID and unique file names on iOS
@interface NSString(UUID)
+ (NSString *)stringWithUUID;
+ (NSString *)stringWithUniquePath;
@end
#import "NSString+UUID.h"
@implementation NSString(UUID)
+ (NSString *)stringWithUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
+ (NSString *)stringWithUniquePath {
NSString *unique = [NSString stringWithUUID];
return [NSTemporaryDirectory() stringByAppendingPathComponent: unique];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment