I inherited an iOS project that uses Core Data. This project has 8 different data models, no need to say that the project is not that big and that I can not see any good reason for splitting the entities over so many data models.
I am trying to use Encrypted Core Data with the current data models and persistent store coordinators and it is not working at all. Every data model is initialized like this:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"First"
withExtension:@"momd"];
self.model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
// Coordinator
//NSPersistentStoreCoordinator *psc = [EncryptedStore makeStore: self.model passcode: @"pass"];
[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.model];
NSURL *storeURL = [[[AppDelegate appDelegate] applicationDocumentsDirectory] URLByAppendingPathComponent: @"First.sqlite"];
NSError *error = nil;
[psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:nil
error:&error];
NSManagedObjectContextConcurrencyType ccType = NSMainQueueConcurrencyType;
self.context = [[NSManagedObjectContext alloc] initWithConcurrencyType:ccType];
[self.context setPersistentStoreCoordinator:psc];
So every data model has its own managed object model and its own persistent store coordinator with its persistent store and context.
What I see is that Encrypted Core Data (ECD) is only creating the tables in the firstly created persistent store. My suspicion is that ECD only handles the persistent stores added to a single coordinator. Based on that assumption I am wondering if it is possible to create a single coordinator and add several stores to it.
I am not that familiar with Core Data but I can't see how that would be possible since the coordinator is initialized with the managed object model (that points to a specific data model file containing only a set of the total number of entities in the project).
Any ideas? I really would like to avoid merging all the data models into a single one in order to use a single managed object model and coordinator (Actually I would like to do it but I am sure it would break everything and I don't really have to time for that right now).