【问题标题】:lightweight migrations swift2 xcode7轻量级迁移 swift xcode 7
【发布时间】:2015-07-31 10:01:54
【问题描述】:

我必须在我的 coreData 项目中添加一个实体,但我不明白如何快速进行轻量级迁移。我被困在第 8 点,我如何将该代码从objective-c 转换为swift?谢谢!

1-打开您的 .xcdatamodeld 文件

双击编辑器

3-选择添加模型版本...

4-添加模型的新版本(添加的新数据模型组)

5-选择主文件,打开文件检查器(右侧面板)

6-在版本化核心数据模型下选择您的新数据版本 当前数据模型的模型 7-这不是全部)您应该执行所谓的“光迁移”。

8-转到您的 AppDelegate 并找到创建 persistentStoreCoordinator 的位置

9-如果 (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) 找到这一行

10-用@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}替换nil选项(实际在该方法的注释代码中提供)

11-给你,玩得开心!

【问题讨论】:

    标签: ios swift core-data-migration


    【解决方案1】:

    在模板项目中,创建持久存储的行是

    if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
    

    要执行轻量级迁移,您必须将以下字典作为 options 参数传递,而不是 nil

    [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
    

    【讨论】:

    • 这是第二个,紧跟在options:之后的那个
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多