Close

So, how can we help you?

Tell us a little about you and your project and we will get back to you quickly.

Send
Read/Write data on the iPhone: Property Lists, SQLite, or Core Data?

September 3rd, 2009 Jeremy Jeremy

Cam

I just want to read and write data in my iPhone app.

You can’t do that without making a fateful choice. There are three major options: Property Lists, SQLite, and Core Data. Core Data is Apple’s preferred method but it doesn’t work on non-OS 3.0 devices. This means a lot of iPod Touch users (who have to pay to upgrade) will miss out on your application and you’ll miss out on their money. The following is a brief comparison of the three options based on my limited understanding.

Property Lists

appData.plist - MakeTheGrade Property lists (aka plists) are simple. A plist is simply a list of nested key-value pairs which can contain common data types like Strings, Numbers, Arrays and Dictionaries.

Procedure
Read data from a plist file, turn the data into objects and display the object data in your UI. Set it up so that when objects are modified, the plist is also modified.

Pros

  • Simple to understand.
  • Easy to work with.

Cons

  • Cannot run complex queries on them (at least not easily).
  • You have to read the entire file into memory to get any data out of it and save the entire file to modify anything in it.

Plist Tutorials

Bottom line: If you’re just starting out and your app doesn’t use a ton of data, plists are probably the way to go.

SQLite

Book.m - SQLiteBooksUntil CoreData came along, this was the popular way to read and write data in iPhone applications. If your a web developer, this ain’t nothing new.

Procedure

Set up the SQLite database (tables and that kinda thing), set up the database connection, query the database, turn those queries into objects in your application, display object data in the UI, do some funky stuff to get object data saved back to the database.

Pros

  • Unlike plists, you don’t have to load the whole database up front. This makes SQLite more suitable for applications with lots of data.
  • Better than plists for slicing and dicing data.

Cons

  • Steeper learning curve than plists.
  • Can get tedious to work with.

SQLite Tutorials

Bottom Line: Use if you want to build an iPhone 2.x compatible application with lots of data.

Core Data

CoreDataBooks.xcdatamodel - CoreDataBooks

Its new, its exciting, and its probably what most developers will use from here on out.

I have not spent enough time with CoreData to summarize it; check out the tutorials (below) to learn more about it.

Pros

  • Nearly all the benefits of SQLite with a lot less hassle (Apple does a lot of the dirty work for you).
  • As Apple’s preferred method it has a lot more official documentation and sample code (it seems the articles and sample code for the other two methods have mysteriously disappeared from Apple’s website).
  • Probably more pros, comments please.

Cons

  • Steeper learning curve than plists.
  • Killer: only works on iPhone OS >3.0. Its killer if your market consists largely of iPod Touch users (who have to pay for upgrades).

Core Data Tutorials

Bottom line: use if you are making an iPhone 3.0 only app.

And the Winner is…

I have messed and dabbled and toiled and troubled with this question for months. At first, I tried SQLite because it seemed to be the way to go at the time. It was great but it seemed overkill for my simple application and managing all that extra code was hassling me to death.

Then came the new guy that everybody was talking about: Core Data. It was everything a programmer could dream about for reasons I couldn’t possibly comprehend at the time. It was the new way to do things and the best thing since sliced arrays, so I tried it.

Everything was going great and I was definitely seeing some benefits over SQLite but it was then when my dreams were quickly shattered by a simple fact: Core Data only works on iPhone 3.0. Ahh, you say, but the adoption rate of iPhone 3.0 is off the charts. Ahh, I say, but you forget that my target market is college students, most of whom:

  • Own iPod Touches because they can’t even afford deodorant, let alone an iPhone.
  • Haven’t upgraded to iPhone 3.0 because they don’t want to pay ten colossal bucks.

I am a college student and I am among these creatures every day. Believe me, its true.

Bottom line: I ended up choosing property lists because (1) I didn’t need the power of SQLite and (2) I didn’t want to alienate my potential iPod Touch buyers who have not yet upgraded to OS 3.0.

clicking on ".more" toggles class "visible" on "#popover" clicking on ".pageCover" removes class "visible" on "#popover"