July 14, 2020

Troubleshooting a Sqlite issue while developing in Xcode

If you see a “Failed to initialize the application’s saved data” and “The model used to open the store is incompatible with the one used to create the store.”  I have found that its referring to the fact that the database table has changed since the last time the simulator ran or the iOS device was testing this application.  Sometime a CLEAN doesn’t help this issue.

What I’ve been doing is to locate and remove the database files from the application directory on my machine running Xcode if the issue is with a simulated device (e.g. iPhone 6).  You will see the actually application directory for the device in the Console messages mixed in with the errors.

Troubleshooting Sqlite issues while developing in Xcode.
Troubleshooting Sqlite issues while developing in Xcode.

If you are in a hurry, you can simply switch to another simulator device that hasn’t had the application deployed to it in the past (i.e. won’t have the old database structure).  For me, I rarely use the iPhone 5, so I switch to it and the application fires right up without a problem.

xcode-simulated-devices
xcode-simulated-devices

Worst case scenario is when the application that you’ve been testing is already on a physical iOS device. When it happens, I don’t bother figuring out where the files are on the device. I just delete the application and push a new version back onto it. All is usually well after that.