views:

1178

answers:

4

So i'm working on a project where there is data visualization.

My ultimate goal is that i have a set of data shipped with the download of the iphone app. But i want it connected to a backend, that if the iphone has a connection with the internet. it can sync the changes from the backend.

The syncing is no problem or the connection between the backend & the iphone.

But what should i use as data storage on my iphone? what is the best way. my data is purely text and doesn't have to be secure.

But it's main feature should be updating certain parts of data ( adding and deleting are not so important )

so what is the easiest (read: least time consuming development ) or the best way?

  • sqlite?
  • plist?
  • ..?
A: 

For a small amount of data (aka you'd feel comfortable loading it all into memory), I'd store the data using the NSUserDefaults persistence mechanims, which can easily handle serialization and storage of standard data structures on application startup and shutdown. It's very simple/quick to use.

For larger datasets that shouldn't be loaded into memory at one time, sqlite seems reasonable.

Brian Ferris
The data can grow up to 1mb, isn't that to much for NSUserDefaults ?Is there a good practice to save data structures ( such as dictionary's or arrays) in sqlite?
Andy Jacobs
+3  A: 

Best results will probably be achieved with SQLite. You can store the initial database in the app itself and copy to the Documents folder. Request deltas from the server at startup to keep the database in sync. For one-way sync, storing a version field and then asking the server for the SQL statements to execute for that version should be sufficient; for two-way sync, something more complicated will probably be necessary.

rpetrich
A: 

Another approach would be to use the NSDictionary method writeToFile; which will write an NSDictionary (which sounds like it would solve your storage needs). Then to reinflate the data on startup you would get a path to the plist file (written by writeToFile) and then the NSMutableDictionary initWIthContentsOfFile: path.

Take a look in "iPhone SDK Application Development", by Jonathan Zdziarski, at Chapter 11: Application Settings. Or take a look at the more detailed File and Data Management chapter of Apple's iPhone Application Programming Guide.

I was in the same boat as you, thinking I'd need SQLLite to store data downloaded from a web service. I replaced the web service with a simpler process that handles JSON requests and returns my data in an NSDictionary format. Then I use the JSON SDK 2.2 for the iPhone to take the incoming JSON data and store it in an NSDictionary. Then when I can easily store the data in the plist as mentioned above.

This is working for me, but depending on what you are doing with your data maybe you need something different.

Good luck.

Mark Thistle
A: 

plist is very simple way to use. refer to http://github.com/samsoffes/iphone-plist

Here is one sample project to use GAE with plist.http://www.ibm.com/developerworks/web/library/wa-aj-iphone/

Forrest