I have an issue with SQLCipher db encryption and CoreData: When I use persistent store coordinator with SQLCipher, it always crash with fault one-to-many relationship after first app relaunch. So when I first time launch the app, I create NSManagedObjects with relationships, then, when I save db, and reopen the app, it crash when I try to access to these relationship. Without SQLCipher everything works fine.
Here is the code for SQLCipher persistent store initialize:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (!_persistentStoreCoordinator) {
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyApp.sqlite"];
NSDictionary *options = @{EncryptedStorePassphraseKey: @"MyApp",
EncryptedStoreDatabaseLocation: storeURL};
NSError *error;
_persistentStoreCoordinator = [EncryptedStore makeStoreWithOptions:options managedObjectModel:[self managedObjectModel] error:&error];
if (error) {
NSLog(@"%@", error);
}
}
return _persistentStoreCoordinator;
}
Code where I create NSManagedObject:
- (id)createObjectWithClassName:(NSString *)name
{
NSManagedObject *object = [[NSClassFromString(name) alloc] initWithEntity:[NSEntityDescription entityForName:name inManagedObjectContext:self.context] insertIntoManagedObjectContext:self.context];
return object;
}