When developing iPhone applications which require data to be stored, nine out of ten times I will use a SQLite database (which uses a file as your database). The best way I’ve found to set this up is when you run your application, check if the database file already exists. If it doesn’t, create a copy of the default one in your project and then in the future use this file (which is now located within the application directory).
This can be an issue for developers when debugging as it’s not always clear exactly what is in the database after you have ran your code and one good way to see this is to simply open the SQLite file. When developing to the iPhone Simulator this file is easily accessible as the app you build is kept in this directory: /Users/username/Library/Application Support/iPhone Simulator/iOS version/ApplicationsiPhone Backup ExtractorHowever when building to a device, it’s not quite as simple to get at the file. This is because you can’t access the application directory on the device directly, so the first step is to download the iPhone Backup Extractor. This awesome tools allows you to extract all application data from backups that iTunes makes from your iOS devices (included within this data is your SQLite database and all other files).
Once you’ve downloaded it, we need to make sure that encryption is turned off on your device backups (as this is not supported). Plug your device in and open up iTunes. Select your device under Devices and scroll down on the summary tab to the options and untick “Encrypt iPhone backup” if it is selected. Now we need to make a backup to get the latest data off your device, so right click on your device (in the left bar) and select “Back Up” to do this.
Extract the iPhone Backup Extractor app from the download you got earlier and run the file. Press the button labelled “Read Backups” and select your device from the list given (if you do not see your device here you probably haven’t backed it up – or encryption could be turned on in your backups). It will then ask you to choose from a list of application names (which are listed using their “Bundle ID”). This should look something like this:
iPhone Backup Extractor – Read Backup
Notice that you can see every app’s “Bundle ID”! Find the app you’re debugging and click the button labelled “Extract”. You will then be prompted to give a location to extract too. So choose somewhere (this doesn’t really matter too much as chances are you will delete it after you’ve debugged anyway), and then click “Extract Here”. A finder window should appear showing you a copy of all the files from your device backup which you can now use to debug!