Reputation: 4173
I plan to use CoreData
API for storing files in my iOS
app. I want to have two stores of data: first, large, but possibly temporary, for caching; and second - small, but I want to ensure the data is persistent and never deleted. What are the best practices for doing this?
Upvotes: 2
Views: 1107
Reputation: 119021
You need to create 2 separate Core Data 'stacks' - i.e. 2 different models (assuming the stored data is different in each), persistent stores, persistent store coordinators and managed object contexts. Both stacks will save the model to a file, but your temporary file should save into NSTemporaryDirectory
(or perhaps better a cache directory) whereas your permanent file should be saved into NSHomeDirectory
.
Other than that the usage of Core Data is nothing special. You just need to use the appropriate managed object context for the data you are saving / retrieving.
If you wanted to move any objects from one store to the other you would need to write the code to do that (i.e. get the object, create a new object in the other store and then copy each attribute across - use dictionaryWithValuesForKeys:
and setValuesForKeysWithDictionary:
).
Upvotes: 2