database - How to dynamically create an auto increment primary key for item id in iOS? -
database - How to dynamically create an auto increment primary key for item id in iOS? -
i have database storing list of items. want give id each of these items , fetch / update details of item db.
i have used appcoda's sqlite db manager , doing in mvvm way.
so, how maintain track of item id or auto increment id everytime? tried include id variable in viewdidload, but, gets reinitialized everytime app loads. primary key cant unique.
how resolve issue?
thanks
you can utilize nsuserdefaults keys, never gets destroyed until app uninstalled,
suppose have id 'int itemid = 1' can save in nsuserdefaults so,
[[nsuserdefaults standarduserdefaults] setvalue:[nsnumber numberwithint:itemid] forkey:@"id"]; [[nsuserdefaults standarduserdefaults] synchronize];
every time need write these 2 lines when want update id's count.
fetch value userdefauts
int itemid = [[[nsuserdefaults standarduserdefaults]valueforkey:@"id"]intvalue];
ios database sqlite primary-key viewdidload
Comments
Post a Comment