Sam Parrish
Sam Parrish

Reputation: 1387

Storing data on iPhone/ iPad

I want to develop an app that can download a load of data at start up, and then display that data throughout the app, dependent on where the user is.

The data will contain info such as clients, invoices, stock, etc., but I want to download the data all in one go, to save having to keep downloading/ transferring data. This also gives the user the ability to work offline.

My question is: what is the best way to store this data on iOS? I have looked into CoreData, but wanted to know if that is the correct path before I commit too much time to learning all about it.

Upvotes: 2

Views: 381

Answers (5)

TechZen
TechZen

Reputation: 64428

Core Data is almost always the way to go. It has a learning curve but after you climb it, Core Data makes everything easier.

Core Data is not just a persistence API, it is an API for creating the entire model layer of a Model-View-Controller design app (which the Apple API employs.) So, once you learn Core Data, you have a very quick and easy way to generate the logical "guts" of the application. Learning Core Data will provide a significant boost to the speed of development and the reliability and maintainability of your apps.

However, real-world constraints of available skill sets and times can force you to choose other options. See this previous answer for a breakdown of when to use Core Data versus other methods.

Upvotes: 3

Simon Lee
Simon Lee

Reputation: 22334

CoreData is the most commonly used data store but it all depends. For instance if you have lots of PDF's you wish to download then you wouldn't put those in CoreData per se, but you would save the files to the users documents directory and commonly add the details (name, path etc) in CoreData for fast retrieval.

For more normal data such as customer details, addresses etc then you can use CoreData to easily go from your domain layer (Customer Object, Address Object) to a persistent store.

CoreData is worth the reading in my opinion. If you want a quick start then I have sample code which includes a Storage Service in the code for this article. Feel free to use it / hack it apart / let me know your thoughts on it! ;) Good luck!

Upvotes: 0

darksky
darksky

Reputation: 21019

There are many different ways. To start off, I would recommend you download the data using JSON or RSS. Once you download it, you can either use Core Data, SQLite or Plists.

I would recommend Core Data over SQLite. So basically it's Core Data vs. Plists. Now if you want to run complex queries, use Core Data. If all you want to do is store simple data, in forms of arrays/dictionaries (can also be nested), then go for Plists.

This link should be useful. Go over it.

Upvotes: 0

Piotr
Piotr

Reputation: 4963

Core Data is good for most things and will do unless you really need to optimize data storage and access, and since you should optimize last this is what I would do in your case.

Upvotes: 0

Joris
Joris

Reputation: 6286

All depends on what you want to do with your data and what format it is in.

Either you:

  • dump the binary files directly on the device (for instance for pdf's or jpgs)

  • create classes implementing NSCoding and use NSKeyedArchiver to store them (for instance for data retrieved from a webservice)

  • use core data to store the date. This is handy if you have more complex relations between your objects and/or want to search/filter your dataset

Upvotes: 1

Related Questions