iphone - Retrieve core-data model version from appDelegate -
anybody knows how core-data model version when app starts?
i've implemented lightweight migration , works fine need check if sqlite db based old model version before migration process starts.
in new model added new entity need populate value of entity of old model. want 1 time.
is there way in appdelegate?
thanks, max
i solved setting db-version in preferences (.plist). if change db, set new db-version in there , store version last start in nsuserdefaults
.
nsnumber *newdbversion = [[[nsbundle mainbundle] infodictionary] objectforkey:@"dbversion"]; nsnumber *olddbversion = [[nsuserdefaults standarduserdefaults] objectforkey:@"dbversion"]; if (olddbversion == nil) { // part without handling, know max db version. }else { if([olddbversion intvalue] < [newdbversion intvalue]) { // try liteweight migration , if failed, migrate hand } }
Comments
Post a Comment