【问题标题】:How to override the NSPersistentStoreCoordinator in UIManagedDocument如何覆盖 UIManagedDocument 中的 NSPersistentStoreCoordinator
【发布时间】:2014-07-04 02:56:09
【问题描述】:

我有一个通过 UIManagedObjectDocument 使用 Core Data 的应用程序。我正在尝试使用加密核心数据 (https://github.com/project-imas/encrypted-core-data) 为基础 SQLite 数据库添加加密。从 ECD 的描述中,我需要创建一种新类型的 NSPersistentSroreCoordinator。但是,我似乎无法使用 UIManagedObjectDocument 执行此操作,因为它会创建自己的内部 NSPersistenStoreCoordinator(标记为私有)。

我用这一行创建数据库:

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

有人知道正确的方法吗?

谢谢!

【问题讨论】:

    标签: sqlite encryption uimanageddocument


    【解决方案1】:

    我要说这是不可能的。 UIManagedDocument 很好地包装了所有内容,对于常见情况可以节省大量时间,但为了实现我的场景,我创建了一个类似于 UIManagedDocument 的 EncryptedManagedDocument 类,但让我可以控制创建自己的持久存储协调器。

    谢谢大家。

    【讨论】:

      猜你喜欢
      • 2011-12-14
      • 2013-04-15
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 2021-06-26
      • 2020-08-29
      • 1970-01-01
      • 2015-09-09
      相关资源
      最近更新 更多