我必须在第一个版本中启用版本控制才能在后续版本中使用轻量级迁移吗?
我担心的是后续版本中数据模型的变化。
我在 Xcode 中创建了一个新的 xcdatamodel 文件,默认情况下该文件没有版本控制。我知道你可以点击某个地方并将其设为“第一个版本”。在“组和文件”树中,xcdatamodel 文件左侧有一个黑色粗箭头,您可以单击该箭头查看内部的所有版本。
我的文件没有那个粗箭头,因此没有版本控制。
这会导致以后出现大问题吗?是否需要从一开始就对其进行版本控制,以便以后能够进行轻量级迁移?一旦应用程序交付给用户,就无法再更改。
My fear is the change of the data model in subsequent releases.
I created a new xcdatamodel file in Xcode which is not versioned by default. I know you can click somewhere and make it "the first version". In the Groups and Files tree the xcdatamodel file gets a thick black arrow on the left side which you can click to see all the versions inside.
My file does not have that thick arrow so is not versioned.
Does this cause big problems later? Is it needed to version it right from the start to make lightweight migration work later? Once the app is shipped to users this can't be changed anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要在第一个版本中设置轻量级迁移。当您决定迁移时,您需要做两件事。首先,您必须保留数据模型的每个版本的副本。这些模型通常保存在 .xcdatamodeld 文件中。或者,您可以只保留一堆 .xcdatamodel 文件。但是,最好使用 .xcdatamodeld 文件来保持一切井井有条。其次,您必须使用持久存储协调器激活轻量级迁移。创建持久性存储协调器时,您将执行如下操作:
请记住,轻量级迁移只能做这么多。如果您需要进行较大的更改,那么您将需要创建一个映射模型。
You do not need to set up lightweight migration in your first release. When you do decide to migrate, you need to do two things. First, you must keep a copy of each version of your data model. These models are usually held in a .xcdatamodeld file. Alternatively, you can just keep a bunch of .xcdatamodel files. However, it's best to use the .xcdatamodeld file to keep everything organized. Second, you must activate lightweight migration with your persistent store coordinator. When creating your persistent store coordinator, you will do something like the following:
Remember that lightweight migration can only do so much. If you need to make heavier changes, then you will need to create a mapping model.