Automatically generated user id [closed]
I am making an iphone application in which there is use of database. I want that whenever user put his or her information, there should be unique id no for each user. But this id no should generate automatically.
How can I do this..please help me.
Thanks alot.
You can get a unique ID by doing this:
NSString *uniqueID = [[NSProcessInfo processInfo] globallyUniqueString];
NSLog(@"%@", uniqueID);
Since you will be using SQLite for your database specific, you could make use of the auto increment present in SQLite for generating id automatically.
I prefer you to use uuid for each user. If you don't know about uuid check it may be this will fulfill your requirements.
see if this answer How to save a video taken from camera into sqlite database in iphone helps.
You can certainly take the unique Id generation from that link.
Have a look at the following example.
http://iosdevelopertips.com/general/create-a-universally-unique-identifier-uuid.html
this generated string + number unique string.
If you want only numbers then i guess you have to use current timestamp + some auto-generated random number string.
精彩评论