博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在iphone里写文件,需要生成唯一的文件名。

一种方法事采用UUID

 

+ (NSString *)GetUUID
{
  CFUUIDRef theUUID = CFUUIDCreate(NULL);
  CFStringRef string = CFUUIDCreateString(NULL, theUUID);
  CFRelease(theUUID);
  return [(NSString *)string autorelease];
}

来源 http://stackoverflow.com/questions/427180/how-to-create-a-guid-uuid-using-the-iphone-sdk

 

另一种方法用具体的时间生成文件名

 

[[NSCalendarDate calendarDate] descriptionWithCalendarFormat:@"%m%d%Y%H%M%S%F"]

http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/DatesAndTimes/Articles/LegacyNSCalendarDate.html

来源:http://stackoverflow.com/questions/3298022/generate-unique-temporary-file-paths

posted on 2011-05-20 15:20  Likwo  阅读(854)  评论(0编辑  收藏  举报