相关疑难解决方法(0)

为核心数据(iPhone)实施"自动轻量级迁移"

当我向核心数据模型添加新属性时,我想让我的应用程序能够进行自动轻量级迁移.

在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)

iphone data-migration core-data

50
推荐指数
2
解决办法
2万
查看次数

如果我已经发布的v1没有版本化的Core Data模型,我可以使用"自动轻量级迁移"吗?

如果我已经发布的v1没有版本化的Core Data模型,我可以使用"自动轻量级迁移"吗?

如果是,是否有任何密钥更改为我需要应用的文档化步骤?

migration iphone core-data ios xcode4

5
推荐指数
1
解决办法
1779
查看次数

标签 统计

core-data ×2

iphone ×2

data-migration ×1

ios ×1

migration ×1

xcode4 ×1