3

I have an application that uses Core Data through UIManagedObjectDocument. I am trying to add encryption to the underlying SQLite database by using Encrypted Core Data (https://github.com/project-imas/encrypted-core-data). From the description for ECD, I need to create a new type of NSPersistentSroreCoordinator. However, I cannot seem to do this with a UIManagedObjectDocument since it creates its own internal NSPersistenStoreCoordinator (which s marked private).

I create the database with this line:

UIManagedDocument* managedDoc = [[UIManagedDocument alloc] initWithFileURL:url];

I tried subclassing UIManagedDocument and creating it this way with no luck:

UIManagedDocument* managedDoc = [[EncryptedManagedDocument alloc] initWithFileURL:url];

And my implementation of the class:

@interface EncryptedManagedDocument()
@property (nonatomic,retain,readonly) NSPersistentStoreCoordinator *encryptedStoreCoordinator;
@end

@implementation EncryptedManagedDocument

@synthesize encryptedStoreCoordinator = _encryptedStoreCoordinator;

-(NSPersistentStoreCoordinator*)encryptedStoreCoordinator
{
    if (_encryptedStoreCoordinator)
        return _encryptedStoreCoordinator;

    _encryptedStoreCoordinator = [EncryptedStore makeStore:[self managedObjectModel]:@"SOME_PASSCODE"];
    return _encryptedStoreCoordinator;
}

-(NSPersistentStoreCoordinator*)persistentStoreCoordinator
{
    return self.encryptedStoreCoordinator;
}
@end

Does anyone know the right way to do this?

Thanks!

Ian
  • 841
  • 5
  • 10

1 Answers1

0

I'm going to say this is not possible. UIManagedDocument wraps things up nicely and is a great time saver for the common case, but to enable my scenario I created an EncryptedManagedDocument class that is similar to UIManagedDocument but gave me control to create my own persistent store coordinator.

Thanks, everyone.

Ian
  • 841
  • 5
  • 10