生成唯一的临时文件路径
我想在 Objective-C 中生成唯一的文件路径。我查看了 NSTemporaryDirectory()
但我能得到的最接近的是 这个和
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用当前系统日期和时间创建文件名 (
[[NSCalendarDate calendarDate] descriptionWithCalendarFormat:@"%m%d%Y%H%M%S%F"]
) ....包括偶数毫秒...使用返回字符串作为唯一文件名...阅读有关日期格式的更多信息 -> http://developer.apple.com/ iphone/library/documentation/cocoa/Conceptual/DatesAndTimes/Articles/LegacyNSCalendarDate.html
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