Apple 的文档为设置(自动)轻量级迁移提供了以下示例:
NSError *error = nil;
NSURL *storeURL = <#The URL of a persistent store#>;
NSPersistentStoreCoordinator *psc = <#The coordinator#>;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
BOOL success = [psc addPersistentStoreWithType:<#Store type#>
configuration:<#Configuration or nil#> URL:storeURL
options:options error:&error];
if (!success) {
// Handle the error.
}
但是我使用的是 RestKit,它在幕后处理持久存储的创建。我的初始化代码的简化版本如下所示:
// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:rootURL];
// Create the object store
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName
usingSeedDatabaseName:seedDatabaseName
managedObjectModel:nil //Don't need to pass it in. It is infered
delegate:self];
// Create Mappings
...
// Define Relationships
...
// Set Mappings
...
鉴于 RestKit 在幕后创建了 persistantStore,我应该在哪里传递配置选项?