我有一個通過UIManagedObjectDocument使用Core Data的應用程序。我試圖通過使用加密核心數據(https://github.com/project-imas/encrypted-core-data)將加密添加到基礎SQLite數據庫。從ECD描述中,我需要創建一個新的NSPersistentSroreCoordinator類型。但是,我似乎無法使用UIManagedObjectDocument來做到這一點,因爲它創建了自己的內部NSPersistenStoreCoordinator(標記爲private)。如何覆蓋UIManagedDocument中的NSPersistentStoreCoordinator
我創建數據庫這一行:
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
有誰知道正確的方法來做到這一點?
謝謝!