Search code examples
objective-cnsstringuniquetemporary-files

Generate unique temporary file paths


I want to generate unique file paths in Objective-C. I looked at NSTemporaryDirectory() but the closest I could get was to this and this. But in the second one they create such a file. I do not want to create it, I just want an NSString for a unique writable path... I don't need paths to folders, just files. How is this possible?


Solution

  • You can create file name using present system date and time ([[NSCalendarDate calendarDate] descriptionWithCalendarFormat:@"%m%d%Y%H%M%S%F"]) .... this include even milliseconds ... use returning string as unique file name ....

    Read more about date formates -> http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/DatesAndTimes/Articles/LegacyNSCalendarDate.html