我正在尝试更新实现核心数据存储的应用程序.我正在为其中一个实体添加一个属性.
我将以下代码添加到我的委托类:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Shoppee.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Error: %@",error);
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
Run Code Online (Sandbox Code Playgroud)
这来自以下网址: Doc
执行代码时出现以下错误:
2009-12-01 20:04:22.877
Shoppee [25633:207]错误:错误
Domain = NSCocoaErrorDomain Code = 134130 …
当我向核心数据模型添加新属性时,我想让我的应用程序能够进行自动轻量级迁移.
在Apple的指南中,这是我能找到的主题的唯一信息:
自动轻量级迁移
要请求自动轻量级迁移,请在addPersistentStoreWithType中传递的选项字典中设置适当的标志:configuration:URL:options:error:.您需要将与NSMigratePersistentStoresAutomaticallyOption和NSInferMappingModelAutomaticallyOption键对应的值设置为YES:
NSError *error;
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];
if (![psc addPersistentStoreWithType:<#Store type#>
configuration:<#Configuration or nil#> URL:storeURL
options:options error:&error]) {
// Handle the error.
}
Run Code Online (Sandbox Code Playgroud)
我NSPersistentStoreCoordinator以这种方式初始化:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"FC.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] …Run Code Online (Sandbox Code Playgroud)