iOS Magical Record & SQLCipher
Asked Answered
W

1

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.

Warman answered 21/8, 2013 at 18:49 Comment(0)
T
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.

Thom answered 21/8, 2013 at 19:16 Comment(3)
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 MagicalRecordWarman
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.Thom
@Warman Could you add an answer instead with the exact setup that worked for you ?Mercymerdith

© 2022 - 2024 — McMap. All rights reserved.