Property list or sqlite for static data?
Asked Answered
T

7

10

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.

Tenderhearted answered 1/6, 2009 at 13:43 Comment(0)
C
14

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!

Craigcraighead answered 1/6, 2009 at 14:8 Comment(1)
Thanks Alex for the thorough answer!Tenderhearted
H
1

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.

Hawkshaw answered 1/6, 2009 at 14:17 Comment(0)
G
1

Don't forget with 3.0 you can use a CoreData layer around SQLlite which may make it more appealing to you.

Gypsy answered 1/6, 2009 at 20:35 Comment(0)
O
1

If you don't need to store any relational information about your data, why not just use files? There will be some wasted filesystem space, but plain files might be the most memory and CPU efficient solution, depending on the size and number of your items.

Outstanding answered 3/6, 2009 at 7:43 Comment(0)
S
0

I've never developed an iPhone app but I have played around in the filesystem. I have seen sqlite databases floating around various places of the phone. I'm pretty sure it uses a sqlite database to store your calendar entries.

Starlet answered 1/6, 2009 at 13:46 Comment(0)
N
0

I would use sqlite. It is already there, easy to use, and will provide the most flexible path for expansion in the future.

I use sqlite for static data in my iPhone apps all the time.

Nowadays answered 1/6, 2009 at 13:46 Comment(0)
E
0

All I did was save state when the app is shut down. I used a file for that.

sqlite sounds perfect for your app. sqlite is pretty easy. I've used it in Adobe AIR apps.

Etrem answered 1/6, 2009 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.