4

I have a list of objects that can sometimes change, and I want to keep a persistent cache on the device whenever the app is closed or move to the background. Most of the objects in the list will not change, so i was wondering what is the best way to save the list. I have two major options i think about:

  1. Using NSKeyedArchiver / unArchiver - This is the most convenient method, because the objects i'm serializing hold other custom objects, so this way i can just write a custom encode method for each of them. The major problem is that i didn't find on Google how to serialize only the changed objects, and serializing the entire list every time seems very wasteful.

  2. Using SQLite - this is what i'm currently using, and the worst problem here is that adding \ changing properties of the objects is very complicated, and much less elegant.

Is there any way that i can enjoy the convenience of NSKeyedArchiver but only serialize the changed objects?

Adam
  • 81
  • 1
  • 2
  • Have you considered using core data? NSKeyedArchiver can only read out everything at once. – koo Dec 19 '10 at 13:04
  • Yes, but implementing core data is a major change to my app and a huge overkill. – Adam Dec 19 '10 at 13:19
  • Do you have any recommendation about the size of the list that is still reasonable to use NSKeyedArchiver with? My list will hold about 1000-2000 items, each one of at most 500 bytes. – Adam Dec 19 '10 at 13:21

1 Answers1

0

Like Adam Ko I would suggest using Core Data:
This kind of problem is what it's really good at, after all!

If your cache items are independent from each other, this could be achieved by simply wrapping your cache-items by a thin layer of NSManagedObject (i.e. you could benefit from Core Data with only minor changes to your app).

This wrapper entity could store an archived version of a cache item in an attribute of type NSBinaryDataAttributeType and provide access to the unarchived object through a transient property. See Non-Standard Persistent Attributes for an example.

danyowdee
  • 4,658
  • 2
  • 20
  • 35