Using two different core data models in one iPhone application. How should I do it?

I'm trying to use two different core data models in an iPhone application, I created and correctly configured the first basic data model that uses SQLite as a repository of persistent objects. This works very well, and by default the pre-populated repository loads correctly in tabular form.

Now I want to create another basic data model with a different default pre-populated SQLite repository in order to load it in a different table view in the same iPhone application. How can I complete this task? I read the Core Data documentation and downloaded the sample code, but I did not find anything in this task.

Any code sample useful to solve this problem will be appreciated.

Thanks in advance, Pierce.

+3
source share
1 answer

You can do this in two different ways:

  • You can configure a separate full kernel data stack by actually copying the template code that you already have in AppDelegate.

  • You can add a second sqlite Core Data file to an existing master data stack. This will allow you to access both objects (not tables, this is a graph of objects, not a database) in the same stack. To do this, you add a second call -addPersistentStore...to your method -persistentStoreCoordinatorand make sure your method -managedObjectModelmerges the models in your package.

Update

. AppDelegate, , .

, UIViewController, .

+2

Source: https://habr.com/ru/post/1753337/


All Articles