I have a rather complicated iPhone app that relies on an API to retrieve data from a server and display it to the user. I have about 5 model classes that are used throughout the application - they just extend NSObject.
I want to add some resistance to models so that you can use some parts of the application, even if the device is disconnected - in fact, this is just illustrious caching. I want some instances of my models to be preserved - for example, items that the user has bookmarked, while others should not, for example, hundreds of search results.
Is Core Data the right solution for this? The difficulties that I see are as follows:
- I would have to change the way I instantiate the model throughout the project. I would have to initialize them as part of the context, which does not necessarily make sense if they really come from an external API.
- I need to be careful not to save instances that I don't need. This seems to come down to deleting the Managed Object immediately after its creation (really inconvenient) or using a separate inconsistent context for instances that I don't want to save (better, but still somewhat inconvenient).
I was hoping that I could continue to use my models throughout the application without changing the code, which should not care about durability, but this is not possible given my requirements. An alternative is to create a new set of managed objects in parallel with my existing objects and use Managed Objects for persistance objects - but such duplication never seems to be the right solution.
Should I try to train Core Data in this, and if so, how? Or should I just look at other options - sqlite3 (seems a bit complicated for what I need), user defaults (maybe not what they are for) or even serialize and write my own objects to files (it seems hack-ish).
Thanks for any input!
alex_c
source share