我发现addPersistentStoreWithType
在RestKit的其他地方被调用,并且需要具有相同的选项才能禁用日记功能。就我而言,我是用RKManagedObjectImporter
创建一个种子DB如下:
NSError * error = nil;
NSString * seedFilePath = [[NSBundle mainBundle] pathForResource:@"seed" ofType:@"json"];
NSString * documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString * path = [documentsPath stringByAppendingPathComponent:@"MyDB.sqlite"];
RKManagedObjectImporter * importer = [[RKManagedObjectImporter alloc] initWithManagedObjectModel:_objectManager.managedObjectStore.managedObjectModel storePath:path];
[importer importObjectsFromItemAtPath:seedFilePath withMapping:mapping keyPath:keyPath error:&error];
BOOL success = [importer finishImporting:&error];
if (success) {
[importer logSeedingInfo];
} else {
RKLogError(@"Failed to finish import and save seed database due to error: %@", error);
}
我还在这里看到了-shm和-wal文件甚至使以RKManagedObjectStore上述变更后。它显然不关心用于创建类型RKManagedObjectStore
的_object_manager.managedObjectStore
的选项。
我发现,在RKManagedObjectImporter.m
,该createPersistentStoreCoordinator
方法增加了自己的持久性存储一样,所以我增加了选项字典是:
NSDictionary * options = @{ NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" } };
NSPersistentStore *persistentStore = [persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options error:error];
if (! persistentStore) {
return nil;
}
结束了......嗯,那种至关重要的做因为没有它,种子数据库将丢失数据。现在我的-shm和-wal文件不见了。谢谢,顺便说一句,因为上述答案帮助我追捕其他地点。
显示核心数据堆栈设置的更多代码以及此代码如何与RestKit链接。 – Wain