I need some help understanding CoreData.
Let's say I have MagicalRecords and RestKit installed, and I also have a server, which can return me some posts
. Then I need to save some of those posts
onto device memory, so a user can read the post later on (even with no internet connection). To not rubbish the memory, it's obvious that I should use in-memory storage, which I do. But for saving the posts I definitley want SQLite or something, and it makes me really helpless.
The problem is, Apple do not give much information about how to handle this sort of situatuion, and the googling did not help so far. I'm guessing that I have to make two persistent stores and two configurations: the default and the "saving" ones. I have found a way to make two persistent stores, but now I just don't understand how to work with that: how to create and save enteties in exact store I want, how to transfer them between stores, how will this interact with RK and MR?
Any help will be aprichiated. Links, info, code snippets
In general,
Set up your data model with different named configurations. Each configuration defines a subset of the model that contains one or more of the entities. You do this in the model editor. When you add a persistent store by calling addPersistentStoreWithType:configuration:URL:options:error:
, provide a configuration name for the second argument. Any time you insert a new instance, it will go to the correct persistent store, based on the configuration.
Don't bother with configurations. Instead, after you insert a new instance, use NSManagedObjectContext
's method assignObject:toPersistentStore:
to tell it which persistent store file to use.
It's all up to you. There is no direct framework support. You cannot use assignObject:toPersistentStore:
to reassign an instance to a different store file. You would have to create a new instance in a different store and copy over all attribute values and relationships yourself.
I have no idea how MagicalRecord or RestKit support this, or if they even do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With