私は以下のコードでNSPersistentStore
を作成していnilです。コアデータaddPersistentStoreWithTypeリターンnilは、しかし、エラーがあまりにも
NSPersistentStore * pc = [persistentCoordinator
addPersistentStoreWithType:EncryptedStoreType
configuration:nil
URL:databaseURL
options:options
error:error];
if (*error)
{
NSLog(@"Unable to add persistent store.");
NSLog(@"Error: %@\n%@\n%@", *error, [*error userInfo], [*error localizedDescription]);
}
options
の値は、この時点で*error
{
EncryptedStore = SQLite;
EncryptedStoreDatabaseLocation =
"file:///var/mobile/Containers/Data/Application/0C27F628-3FF0-467F-8EF1-5974EBBD3620/Documents/DBEncrypted.sqlite";
EncryptedStorePassphrase = "xxxxxxxxredactedxxxxxxx";
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
NSSQLitePragmasOption = {
synchronous = OFF;
};
}
でnil
あるとpc
もnil
です。
関数がnilを返す場合、Appleのドキュメントによればエラーになります。誰もそれを見たことがありますか?
EncryptedStoreType
は、我々はデータストアを移行する場合は、エラーにのみ起こるhttps://github.com/project-imas/encrypted-core-data
からである
編集:私は
でそれを呼び出す+ (NSPersistentStoreCoordinator *)makeStoreWithOptions:(NSDictionary *)options managedObjectModel:(NSManagedObjectModel *)objModel error:(NSError *__autoreleasing *)error
{
NSPersistentStoreCoordinator * persistentCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:objModel];
// NSString* appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0];
BOOL backup = YES;
NSURL *databaseURL;
id dburl = [options objectForKey:EncryptedStoreDatabaseLocation];
if(dburl != nil) {
if ([dburl isKindOfClass:[NSString class]]){
databaseURL = [NSURL URLWithString:[options objectForKey:EncryptedStoreDatabaseLocation]];
backup = NO;
}
else if ([dburl isKindOfClass:[NSURL class]]){
databaseURL = dburl;
backup = NO;
}
}
if (backup){
NSString *dbNameKey = (__bridge NSString *)kCFBundleNameKey;
NSString *dbName = NSBundle.mainBundle.infoDictionary[dbNameKey];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *applicationSupportURL = [[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
[fileManager createDirectoryAtURL:applicationSupportURL withIntermediateDirectories:NO attributes:nil error:nil];
databaseURL = [applicationSupportURL URLByAppendingPathComponent:[dbName stringByAppendingString:@".sqlite"]];
}
[persistentCoordinator addPersistentStoreWithType:EncryptedStoreType configuration:nil URL:databaseURL
options:options error:error];
if (*error)
{
NSLog(@"Unable to add persistent store.");
NSLog(@"Error: %@\n%@\n%@", *error, [*error userInfo], [*error localizedDescription]);
}
return persistentCoordinator;
}
:メソッドの 完全なコード
- (void) initCoreDataProperties
{
NSError *error;
// Creating the Managed Object Model from momd
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:TBCoreDataModelFileName withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
// Creating the Encrypted Store Persistent Coordinator
_persistentStoreCoordinator = [EncryptedStore makeStoreWithOptions: [self persistentStoreOptions]
managedObjectModel: self.managedObjectModel
error: &error];
あなたは 'makeStoreWithOptions呼び出す方法であなたの質問更新:managedObjectModel:エラー:'メソッドを、あなたが渡す 'ERROR'値を宣言する方法を含んを – rmaddy
私はあなたがこの問題を解決したかもしれないことを望んで質問 – ppaulojr
を更新しました。そうでなければ、永続的なストアの欠陥を解決するためにプロジェクトに "sqlite3.h"と "sqlite3.c"ファイルを追加する必要があります。 –