Easy Unique File Names
A method for quickly making sure that the file URL you're about to write to is unique. If the file already exists it simply inserts a UUID. You can throw this method in somewhere or create a category on NSFileManager
.
- (NSURL *)uniqueFileURLWithURL:(NSURL *)url
{
if (![self fileExistsAtPath:url.path]) {
return url;
}
NSString *uniquePath = [NSString stringWithFormat:@"%@%@%@", [url.path stringByDeletingPathExtension], [[NSProcessInfo processInfo] globallyUniqueString], url.pathExtension];
return [NSURL fileURLWithPath:uniquePath];
}
I got the inspiration from this StackOverflow question.
Written by Jason Larsen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#