我有一个应用程序,通过UIManagedObjectDocument使用Core Data。我正在尝试使用Encrypted Core Data(https://github.com/project-imas/encrypted-core-data)为底层的SQLite数据库添加加密。根据ECD的描述,我需要创建一种新类型的NSPersistentSroreCoordinator。但是,由于UIManagedObjectDocument创建了自己的内部NSPersistenStoreCoordinator(标记为私有),因此我似乎无法做到这一点。
我使用以下代码行创建数据库:
我尝试通过子类化UIManagedDocument并以此方式创建它,但没有成功:
我使用以下代码行创建数据库:
UIManagedDocument* managedDoc = [[UIManagedDocument alloc] initWithFileURL:url];
我尝试通过子类化UIManagedDocument并以此方式创建它,但没有成功:
UIManagedDocument* managedDoc = [[EncryptedManagedDocument alloc] initWithFileURL:url];
而我的类的实现:
@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
有人知道正确的操作方法吗?
谢谢!