Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property list or sqlite for static data?

Is there any "Best Practice" approach to storing persistent static data for iPhone apps?

I have an app that reads a dictionary of approximately 1000 items many of which are arrays. I started out using a single plist for this and it has become somewhat unwieldy especially since much of the values are HTML strings.

Is there a better way for me to approach this? I plan on scaling this app significantly and I obviously don't want to change my approach midstream.

I've googled for iphone data storage and variants but have come up short for anything even touching on a best practice.

like image 387
ennuikiller Avatar asked Jun 01 '09 13:06

ennuikiller


2 Answers

It sounds like you intend to distribute some data with your application. A property list is probably the easiest to maintain, but it will be loaded into memory all at once. This could eat up a lot of the device's memory.

An sqlite database, on the other hand, will load only the data you request. I'm not sure how your data is structured, but you could quite easily create key-value pairs with a single database table. (A single table with a key column and a value column) Then, if it were me, I'd write an Objective-C class to wrap the database queries so I can write easy statements like:

NSString *welcomeText = [[MyData sharedData] dataWithKey:@"WelcomeText"];

Getting the data into the database in the first place doesn't have to be difficult. You can use the command line sqlite3 utility to bulk load your data. There's a command called .import that will import your data from a text file.

Hope this gets you moving in the right direction!

like image 166
Alex Avatar answered Oct 10 '22 21:10

Alex


I'd go with a sqlite solution. The apps I am working on now, which are just apps to help me learn iPhone development, mostly all use sqlite. I use the sqlite plugin for firefox to help with maintaining the database, which works surprisingly well. https://addons.mozilla.org/en-US/firefox/addon/5817

As Alex suggested using a wrapper class would also be the best way to go.

like image 38
OhioDude Avatar answered Oct 10 '22 21:10

OhioDude