I am using core data for storing. For the second release of my app I created a new entity in my core data,so I used light weight migration. By this my schema was change but user data got lost. How can save my user data?
0
votes
1 Answers
0
votes
You have to put some logic in your appdelegate didFinishLaunching method for new version so that it detects that this is a update and app is opening for first time (you can do this by having some field in userdefaults).
After that you read the current data from user's DB using sqlite queries and store it temporarily.
Then delete the db from file location and instantiate new DB from core data, you need to copy the existing data again to new DB by sqlite query and then its ready to use with old data backed up.