0

I am using sqlite in my IOS project. I am copying the sqlite file from my main bundle to documents directory on launch of the application. It does copy, but suppose if I reset the simulator, the sqlite file from documents directory is also getting deleted, thus all the changes made goes away with it.

Any help would be appreciated.

footyapps27
  • 3,982
  • 2
  • 25
  • 42
  • that's what resetting the simulator does. it removes your apps and their data. if you don't want to lose the database, you shouldn't reset the simulator. – Nate Sep 14 '12 at 06:14
  • so if I do not want to lose the data on reset of the simulator I should save it in some folder other than documents directory?? – footyapps27 Sep 14 '12 at 07:17
  • You should also be aware that the documents directory is backed up to iCloud, so unless that is desired behaviour your sqlite file should be stored elsewhere. – Keab42 Sep 14 '12 at 09:54
  • 1
    so in case of simulator run i should save it somewhere else? But in case of running in device, documents directory is the place to store right? – footyapps27 Sep 14 '12 at 09:57

1 Answers1

1

First, you can readup here on where to save persistent data, and how to prevent iCloud backups. In your case of the simulator, you need to add code to your program wrapped in an 'ifdef SIMULATOR' (I don't have a reference handy on what define to test against, but I know there is one), and save a copy of your file to a fully qualified path that leads to your user account (ie /Users/xyz/iOS/xzy.data). When your app starts up, you first look for the file in the appropriate place as you would on the device. Then, if the file is not found, for the Simulator only, you see if there is a file in that hard coded path, and if so copy it back to the Simulator.

Community
  • 1
  • 1
David H
  • 40,852
  • 12
  • 92
  • 138