使用默认方法(例如persistentContainer)在现有CoreData中添加属性

时间:2018-07-12 17:27:01

标签: objective-c core-data core-data-migration

我在现有CoreData中添加了新属性,并使用默认方法,即应用程序委托文件中的persistentContainer,而不是persistentStorecordinator。所以在哪里添加这些选项:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

我已经在core_data模态中添加了版本号。搜索后,我发现这两个属性默认为 true 是真的吗?

1 个答案:

答案 0 :(得分:0)

Requesting lightweight migration

中所述
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] 
initWithManagedObjectModel:mom];
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, 
                          NSInferMappingModelAutomaticallyOption: @YES};
NSError *error = nil;
if (![psc addPersistentStoreWithType:NSSQLiteStoreType 
                       configuration:nil 
                                 URL:storeURL 
                             options:options error:&error]) {
    NSAssert(NO, @"Unable to load persistent store: %@\n%@", 
             [error localizedDescription], [error userInfo]);
}