使用NSInferMappingModelAutomaticallyOption更改核心数据中的属性类型 [英] Changing Attribute Type in Core Data with NSInferMappingModelAutomaticallyOption

查看:113
本文介绍了使用NSInferMappingModelAutomaticallyOption更改核心数据中的属性类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的核心数据存储,我使用标志'NSInferMappingModelAutomaticallyOption',以便每当我对Core数据模型进行更改时,我首先创建一个新的模型版本,并且自动迁移对数据模型的更改。

I have my Core Data Store and I use the flag 'NSInferMappingModelAutomaticallyOption' so that whenever I make changes to the Core Data Model I first create a new model version, and the changes to the data models are automatically migrated.

但是,我需要更改其中一个实体的属性类型。当我这样做,自动迁移似乎不工作,我得到一个核心数据的错误,当我尝试运行我的应用程序。

However, I need to change an attribute type for one of my Entities. When I do this, the automatic migration doesn't seem to work and I get a Core Data error when I try to run my app.

任何设置方式要继续自动模型迁移?

Any way of setting this up to continue with the automatic model migration?

推荐答案

轻量级迁移不支持属性类型更改:

Attribute type change is not supported by the lightweight migration:


要使Core Data能够生成推断的映射模型,更改必须符合明显的迁移模式,例如:

For Core Data to be able to generate an inferred mapping model, changes must fit an obvious migration pattern, for example:


  • 简单添加新属性

  • 删除属性


  • 重命名实体或属性


  • 可选属性变为非可选属性并定义默认值
  • Simple addition of a new attribute
  • Removal of an attribute
  • A non-optional attribute becoming optional
  • An optional attribute becoming non-optional, and defining a default value
  • Renaming an entity or property



编辑



我假设您使用的是轻量级迁移。但正如斯科特指出的,也许你不是。如果要使用自动迁移(这与轻量级迁移不同),您仍然可以通过提供映射模型来实现此目的。在这种情况下:

Edit

I assume you're using the lightweight migration. But as Scott pointed out, maybe you aren't. If you want to use automatic migration (which is not the same as the lightweight migration), you can still do this by providing the mapping model. In this case:


Core Data将尝试在应用程序包中找到源和映射模型,并执行迁移。 >

Core Data will attempt to locate the source and mapping models in the application bundles, and perform a migration.

但是此迁移不会是轻量级的。 Core Data将打开两个存储(源和目标),并复制内存中的所有实体。所以应用程序消耗的内存取决于商店中的数据量。

But this migration will not be lightweight. Core Data will open two stores–the source and the target–and copy all entities in memory. So the memory consumed by the app depends on the amount of data in the store.

这篇关于使用NSInferMappingModelAutomaticallyOption更改核心数据中的属性类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆