Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save unique image name in document directory

Tags:

ios

In my ios app i am stuck on a task. I need to take pic from camera and save it on document directory.Problem is that i want save unique name of image.I was try to add current time with a name. but there are length problem to save image.Please suggest me how can i do that task.

Thanks

like image 731
M.B Avatar asked Dec 08 '22 15:12

M.B


1 Answers

Given a proposed name like NString *name = @"Lake":

NSString *myUniqueName = [NSString stringWithFormat:@"%@-%u", name, (NSUInteger)([[NSDate date] timeIntervalSince1970]*10.0)];

EDIT: updated so that the only chance of a duplicate is the same original name, submitted within 100 ms of the first (virtually impossible in my opinion, if this is a concern use 100 instead of 10)

like image 91
David H Avatar answered Dec 25 '22 13:12

David H