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.

Subscribe to our Newsletter or RSS feed

10 Responses to “Read/Write data on the iPhone: Property Lists, SQLite, or Core Data?”

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

    You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…

  2. You could also look at OmniGroup's OmniDataObjects framework, which provides a "CoreData-like API", on top of SQLlite, see http://www.omnigroup.com/developer/

  3. Thanks for the indepth info. I think for my Uni app I'll go with Core Data. I think it has some great advantages, plus people will switch in the end, so I don't want to make this over again.

    I hope Apple won't continue to add different methods of r/w data! :)

  4. [...] Read/Write data on the iPhone: Property Lists, SQLite, or Core Data? | Tapity Read/Write data on the iPhone: Property Lists, SQLite, or Core Data? | Tapity. [...]

  5. Alot of bloggers are not really happy with this new iPad.There was too much hoopla about it and lots of people got turned off.You see, I actually see great deal of the awesome potential uses of the gizmo. Third-party soft for doing tunes, games, papers and magazine and FFS books, all kinds of awesome stuff, but IMHO they failed to sell it properly (excluding the books). It feels rather unfinished

  6. Ram says:

    Simply super.

  7. Matthew says:

    There are a lot of Objective-C libraries out there for SQLite but the one I would recommend is https://github.com/ziminji/objective-c-sql-query-builder It make working with an SQLite database way simple and takes out much of the learning curve. It removes a lot of the complexities because the library manages the databases for you and converts most of Objective-C common data types. I think it is the way to go.

  8. cellphone…

    [...]Read/Write data on the iPhone: Property Lists, SQLite, or Core Data? | Tapity[...]…

  9. mesothelioma lawyers san diego…

    [...]Read/Write data on the iPhone: Property Lists, SQLite, or Core Data? | Tapity[...]…