I’m in the process of learning Objective C with the goal of making iOS apps. I’ve come across some great resources so I figured I’d share them here as I go. Today I’m working with Sqlite databases.
I used the tutorial here to get started: SqliteView.zip (.mm): iOS example of using the SQLite framework for writing and reading data from a database on the iPhone.
However, I was having problems making queries and i didn’t like the amount of code that was required to query the database so I went looking for something better and found a wrapper class called FMDB . Ok, so why am I mentioning SqliteView then? It includes good directions on how to add the Mach-0 dynamic library called “libsqlite3.dylib” to your project that you will need anyhow for interacting with Sqlite db’s.
Instead of using command line to create the initial database, I’m using this handy utility: SQLite Database Browser. It’s also helpful for testing and verifying your code is actually updating the database.
All of that got me pretty far along, except when it came to deploying the first time. FMDB’s docs have you create your database with sql queries each time you load. There wasn’t anything that I could find that explained how to use a pre-built database that you include in your resources folder. I ended up finding a solution here: sqlite database initialization issues. It’s a forum thread, but the solution is at the end.
I’m not going to explain how to stitch it all together, mainly because this is still really foreign to me, but it should give a good starting point.
Edit: Forgot one. Didn’t need to use it, but a ton of info: 12 SQLite Resources for iPhone Developers.