As I was doing some development on my iPhone app yesterday night and this morning I ran into an issue that I figured I would blog about and hopefully it may be of use to some stray Googler in the future.
In a nutshell, the issue is that the iPhone Simulator caches the SQLite database in a local Mac OS X directory to improve performance, so I was getting runtime errors about tables not existing from the Xcode Console, which of course was driving me absolutely mad since the SQL file itself in the project bundle showed the database table being there!
After double and triple checking my models and controllers, and verifying that everything was hooked properly in my NIB files, I set out to do some Googling to see if I could determine what could possibly be wrong. As mentioned above, I knew the table in question was in the database, because if you opened the .sql file you could see it plain as day. But at the end of the day it seems that deleting your old database file from Xcode and adding the new one simply may not be enough, as in my case I had to actually go to the directory on my Mac where the iPhone Simulator stores all the files it uses to build the apps and delete the directory of the app I am building. Then, upon re-building, it pulled a fresh copy of my files (with my new database) and voila!
So, where is this mystical iPhone Simulator directory? It’s a bit of a hike but to get there just follow this path:
/Macintosh HD/Users/<username>/Library/Application Support/iPhone Simulator/User/Applications/
Once you’re in there you’ll see a bunch of directories with some cryptic directory names. Just browse around each one until you find the application in question and then delete the one you need to.
That should do it. Once done go back to Xcode and Build/Run and your updated SQLite database should be brought into your project. Hope this information helps someone. Any questions feel free to ask in the comments.