6

I m using Magical Record for saving my data. This data needs encryption, so i m trying to combine it with SQLCipher library(http://sqlcipher.net/ios-tutorial/).

I already setup SQLCipher and tested it with Core Data successfully, using EncryptedStore file from this example https://github.com/project-imas/encrypted-core-data:

What i did was only changed NSPersistentStoreCoordinator like this:

NSPersistentStoreCoordinator *coordinator = [EncryptedStore makeStore:[self managedObjectModel]:[SSKeychain passwordForService:myservice account:myaccount]];

So i think i need to change how NSPersistentStoreCoordinator is created in MagicalRecord, but i had no luck with it, so any help would be appreciated.

1 Answers1

2

If you already have a persistent store coordinator, you will have to setup the core data stack manually when using MagicalRecord. I recommend something along these lines:

 NSPersistentStoreCoordinator *coordinator = //how ever you do it;
 [NSPersistentStoreCoordinator MR_setDefaultCoordinator:coordinator];
 [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];

You may need to expose the initialize method on your own.

As a side note, you may want to add a ticket to the MagicalRecord issues log to add a method to the setup method collection to specify your own coordinator so that this work is taken care of by MagicalRecord itself.

casademora
  • 67,775
  • 17
  • 69
  • 78
  • 1
    I solved the problem myself already. I went step by step through Magical Record and changed in NSPersistentStoreCoordinator+MagicalRecord.m method: + (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options difference: NSPersistentStoreCoordinator *psc = [EncryptedStore makeStore:model:@"temp"]; // NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; Now SQLCipher works with MagicalRecord –  Aug 21 '13 at 20:17
  • yeah, you probably should do that in a "public api" sorta way. If you're cool with maintaining the lib with your custom changes, that's cool. – casademora Aug 21 '13 at 20:33
  • 1
    @user1041311 Could you add an answer instead with the exact setup that worked for you ? – Kiran Apr 10 '15 at 01:41