0

I'm currently looking for the best way to save data in my iPhone application; data that will persist between opening and closing of the application. I've looked into archiving using a NSKeyedArchiver and I have been successful in making it work. However, I've noticed that if I try to save multiple objects, they keep getting overwritten every time I save. (Essentially, the user will be able to create a list of things he/she wants, save the list, create a few more lists, save them all, then be able to go back and select any of those lists to load at a future date.)

I've heard about SQLite, Core Data, or using .plists to store multiple arrays of data that will persist over time. Could someone point me in the best direction to save my data? Thanks!

AWF4vk
  • 5,810
  • 3
  • 37
  • 70
Plaidfox
  • 55
  • 1
  • 10

5 Answers5

2

Core Data is very powerful and easy to use once you get over the initial learning curve. here's a good tutorial to get you started - clicky

Sam Parrish
  • 1,377
  • 1
  • 11
  • 17
  • 1
    I've already created a project that isn't set up to use core data. Is it difficult to set it up in a pre-existing project, or should I just start from scratch, select "use core data" and copy files over? – Plaidfox Aug 19 '11 at 18:50
1

Also you can try this framework. It's very simple and easy to use. It's based on ActiveRecord pattern and allow to use migrations, relationships, validations, and more.

It use sqlite3 only, without CoreData, but you don't need to use raw sql or create tables manually.

Just describe your iActiveRecord and enjoy.

AlexDenisov
  • 4,022
  • 25
  • 31
1

As an easy and powerful alternative to CoreData, look into ActiveRecord for Objective-C. https://github.com/aptiva/activerecord

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
1

I'd go with NSKeyedArchiver. Sounds like the problem is you're not organizing your graph properly.

You technically have a list of lists, but you're only saving the inner-nested list.

You should be added the list to a "super" list, and then archiving the super-list.

CoreData / SQL seems a bit much from what you described.

AWF4vk
  • 5,810
  • 3
  • 37
  • 70
  • So you would suggest pulling what I have for an array in the archive, append the new data to the end, then re-archive it? – Plaidfox Aug 19 '11 at 20:10
  • That's one way of doing it. Or you can always have the super list loaded and modify it as needed. Then when you save, save the entire list. – AWF4vk Aug 19 '11 at 20:46
  • Right now I'm looking at saving mutable arrays that have about 16 strings in them each. Will I have to worry about memory overload if this archived data gets too large? – Plaidfox Aug 20 '11 at 00:52
  • It's the same amount of archive size as an SQL would take. As far as I know, CoreData (which is sqlite) does not compress strings. Even if you have 100 arrays, each having 16 strings, each string will probably be 50 characters. That's 80,000 characters, or 80kb. 1000 strings or 500 characters = 800kb. Still quite small and manageable. – AWF4vk Aug 20 '11 at 06:28
0

You want to check out this tutorial by Ray Wenderlich on Getting started with CoreData. Its short and goes over the basics of CoreData.

Essentially you only want to look at plists if you have a small amount of data to store. A simple list of settings or preferences. Anything larger than that and it breaks down specifically around performance. There is a great video on iTunesU where the developers at LinkedIn describe their performance metrics between plists and CoreData.

Archiving works, but is going to be a lot of work to store and retrieve your data, as well as put the performance challenge on your back. So I wouldn't go there. I would use CoreData. Its extremely simple to get started with and if you understand the objects in this stack overflow question then you know everything you need to get going.

Community
  • 1
  • 1
Matthew Carriere
  • 511
  • 6
  • 13