- The iPhone Developer's Cookbook
(NOTE: don't waste your money) - Beginning iPhone Development
(NOTE: best released book thus far) - iPhone SDK Development
(PDF beta access only at this time
What I find most frustrating / challenging is that none of these books are THE killer iPhone development guide. In fact, it often requires mining tidbits of technique and information from multiple books, Apple examples, and blog postings to find the answer to a problem.
While XCode will place everything inside of the Resources group into your application bundle, the app bundle on the iPhone is effectively read-only. Therefore, when you create a database on the Mac and place it into your app bundle- you can't actually do anything with it. Instead, you're application needs to have a routine to check for the existence of a database (and perhaps a version) and if one isn't found, physically copy over the database from the application bundle into your ~/Documents folder for your application on the iPhone.
As a case in point, the "Beginning iPhone Development" book provides a great section on working with SQLite, but it omits this fact, since its samples actually issue CREATE table statements. That's great for rudimentary work, but let's face it- it is more performant to already have the database tables created and avoid bloating the app with such unnecessary logic.
So the key tip here is simple- if you are doing iPhone development against SQLite, you have 2 options at your disposal:
- Let the SQLite APIs automatically create an empty database file when you issue the open command (occurs by default), and then detect the (lack of) tables and issue the CREATE statements from within your code, or
- Add logic in your app delegate at startup to check for the existence of the database, and if not found- physically copy the template database from your application bundle over to the ~/Documents directory
Happy coding!
