xcode 删除核心数据版本 xcdatamodel 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6712123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:29:46  来源:igfitidea点击:

Deleting core data version xcdatamodel files

iosxcodecore-data

提问by Andrew

I've created a versioned Core Data model in my iOS app, and it has several versions created so far (several .xdatamodel files within the .xcdatamodeld bundle). Before shipping the app, I'm considering deleting these old versions so I can start with a single clean data model - and data loss isn't an issue at this stage.

我在我的 iOS 应用程序中创建了一个版本化的 Core Data 模型,到目前为止它已经创建了几个版本(.xcdatamodeld 包中的几个 .xdatamodel 文件)。在发布应用程序之前,我正在考虑删除这些旧版本,以便我可以从一个干净的数据模型开始 - 在这个阶段数据丢失不是问题。

Is this possible? And what would be the best way to achieve this without simply deleting all Core data files and recreating a new model.

这可能吗?在不简单地删除所有 Core 数据文件并重新创建新模型的情况下,实现这一目标的最佳方法是什么?

回答by Lily Ballard

Deleting the old models means you cannot migrate any existing data stores. I assume you're ok with that given your statement about data loss. If you want to start fresh, you can take the current xcdatamodel, copy it somewhere else (e.g. your Desktop), then delete the xcdatamodeld folder. At this point, you can drag your saved xcdatamodel back into Xcode and re-add it as a non-versioned file.

删除旧模型意味着您无法迁移任何现有数据存储。鉴于您关于数据丢失的声明,我假设您对此没有意见。如果您想重新开始,您可以使用当前的 xcdatamodel,将其复制到其他地方(例如您的桌面),然后删除 xcdatamodeld 文件夹。此时,您可以将保存的 xcdatamodel 拖回 Xcode,并将其重新添加为非版本化文件。

回答by Rein rPavi

If you want to get rid of old versions of the data model

如果你想摆脱旧版本的数据模型

(Note: make sure you copy the Data model file and save it somewhere in case something goes wrong)

(注意:确保复制数据模型文件并将其保存在某处以防出现问题)

Five Step solution

五步解决方案

  1. Select .xcdatamodeld file in Xcode, make sure you have the latest version is set as the current data model.
  2. Right, Click Show in finder if you don't see all your versions right click again and show package contents.
  3. Delete all the version except the latest.
  4. Jump back to Xcode and now delete the .xcdatamodeld file just remove reference don't move to trash.
  5. Add the file back again
  1. 在 Xcode 中选择 .xcdatamodeld 文件,确保您将最新版本设置为当前数据模型。
  2. 对,如果您没有看到所有版本,请单击“在查找器中显示”,再次右键单击并显示包内容。
  3. 删除除最新版本以外的所有版本。
  4. 跳回 Xcode,现在删除 .xcdatamodeld 文件,只需删除引用,不要移动到垃圾箱。
  5. 再次添加文件

Voila it's done

瞧它完成了