Bruno
Bruno

Reputation: 1032

Working with 2 CoreData objects

I need to have 2 separate data bases on my project, so my question is, how can I have more than 1 CoreData data base on the same project? Im asking this since I already have one coredata data base setup. I would be very thankful if I could have an explanation or a tutorial/example on how to address this problem.

Upvotes: 2

Views: 293

Answers (1)

user23743
user23743

Reputation:

To create multiple Core Data stores, you make a separate xcdatamodel schema for each of the data stores. In your application, you need to choose how you separate Core Data "stacks" for each of these schemata:

  • you could have separate NSManagedObjectModel instances, one for each schema; or you could create a merged model that contains the objects from both schemata.
  • you'll need at least one NSPersistentStore and NSPersistentStoreCoordinator for each managed object model - for most practical uses this means either one per model or a single store if you're using a merged model.
  • you then create NSManagedObjectContext instances as you need them, backed by the persistent store coordinator(s).

However, this is iOS, so users of your application will probably never manage or care about how your data stores are organised. Unless you have a technical reason not to, you will find things easier just to define all of your entities in a single Core Data model.

Upvotes: 1

Related Questions