如何在 Xcode 中删除旧的/未使用的数据模型版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7708392/
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-09 04:07:46  来源:igfitidea点击:

How to delete an old/unused Data Model Version in Xcode

xcodecore-dataversion-controlxcdatamodel

提问by SAHM

How can I delete an old Data Model in Xcode? The option is disabled on the menu. (The models I want to delete have not been released to the public - they are interim development models.)

如何在 Xcode 中删除旧的数据模型?该选项在菜单上被禁用。(我要删除的模型尚未向公众发布 - 它们是临时开发模型。)

回答by David Avendasora

It's a hack, but this worked for me:

这是一个黑客,但这对我有用:

  1. Set the Current version of the model in Xcode to one that you want to keep
  2. Remove the .xcdatamodeld from your project (Right-click -> Delete -> Remove Reference Only)
  3. Show the contents of the .xcdatamodeld package in the Finder (Right-click -> Show Package Contents)
  4. Delete the .xcdatamodel file(s) that you don't want anymore
  5. Re-add the .xcdatamodeld file to your project
  1. 将 Xcode 中模型的当前版本设置为您想要保留的版本
  2. 从您的项目中删除 .xcdatamodeld(右键单击 -> 删除 ->仅删除引用
  3. 在 Finder 中显示 .xcdatamodeld 包的内容(右键单击 -> 显示包内容)
  4. 删除不再需要的 .xcdatamodel 文件
  5. 将 .xcdatamodeld 文件重新添加到您的项目中

This eliminates the need to manually modify any of the project metadata files.

这消除了手动修改任何项目元数据文件的需要。

回答by Daniel Wood

I've just found the need to do this. I created a new model version then realised I didn't need it after all. I was surprised to find there was no way of deleting it (that I could find) from Xcode. Still, to remove it I did the following:

我刚刚发现需要这样做。我创建了一个新的模型版本,然后意识到我根本不需要它。我惊讶地发现无法从 Xcode 中删除它(我可以找到)。尽管如此,为了删除它,我做了以下事情:

First I made sure it wasn't my current model version. Then I went to Finder and found my *.xcdatamodeld file. Right click and Show Package Contents on that. In there you will find the actual model file and can delete it.

首先,我确定它不是我当前的模型版本。然后我去 Finder 找到了我的 *.xcdatamodeld 文件。右键单击并在其上显示包内容。在那里你会找到实际的模型文件并且可以删除它。

This still doesn't remove it from Xcode and it will show red in the Files and Groups. To stop this from happening go back to Finder and Show Package Contents on your main *.xcodeproj file (you may want to make sure you have a backup of this first). In there open up and edit project.pbxproj do a find on your model version name, in my case "interval 8". For me it appeared on two separate lines. I removed these lines and now it's completely removed from Xcode.

这仍然不会从 Xcode 中删除它,它会在文件和组中显示为红色。要阻止这种情况发生,请返回主 *.xcodeproj 文件中的 Finder 和 Show Package Contents(您可能需要确保先备份此文件)。在那里打开并编辑 project.pbxproj 对您的模型版本名称进行查找,在我的情况下为“间隔 8”。对我来说,它出现在两条不同的行上。我删除了这些行,现在它已从 Xcode 中完全删除。

回答by Tony

This worked for me in XCode 10.3 without the ordering issue occurring when removing the whole model and adding it again:

这在 XCode 10.3 中对我有用,在删除整个模型并再次添加时不会出现排序问题:

  1. Select any model version other than the one you want to delete.
  2. From XCode, right-click the .xcdatamodeld file and select 'Show in Finder'.
  3. Close XCode.
  4. In finder, right-click the same file and select 'Show Package Contents'.
  5. Write down the name of the model you want to remove, then from Finder, delete it.
  6. Still in Finder, navigate to the project file (.xcodeproj).
  7. Right-click and open with Atomor any other editor.
  8. From the 'Project' pane open project.pbxproj file.
  9. Remove all lines containing the model name you removed (Example: "ABC 17.xcdatamodel"). You will find two lines similar to the following:

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel*/ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "ABC 17.xcdatamodel"; sourceTree = ""; };

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel*/,

    Note if you find a third line it will be something like:

    currentVersion = 9D88880323C545B800A789B9 /* ABC 17.xcdatamodel */;

    That means it is the currently selected model. Never delete this line. Just change the text to another model version.

  10. Re-open XCode.

  1. 选择要删除的模型版本以外的任何模型版本。
  2. 在 XCode 中,右键单击 .xcdatamodeld 文件并选择“在 Finder 中显示”。
  3. 关闭 XCode。
  4. 在 finder 中,右键单击同一文件并选择“显示包内容”。
  5. 记下要删除的模型的名称,然后从 Finder 中删除它。
  6. 仍然在 Finder 中,导航到项目文件 (.xcodeproj)。
  7. 右键单击并使用Atom或任何其他编辑器打开。
  8. 从“项目”窗格中打开 project.pbxproj 文件。
  9. 删除包含您删除的模型名称的所有行(例如:“ABC 17.xcdatamodel”)。您会发现两行类似于以下内容:

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel*/ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; 路径=“ ABC 17.xcdatamodel”;源树 = ""; };

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel*/,

    请注意,如果您找到第三行,它将类似于:

    当前版本 = 9D88880323C545B800A789B9 /* ABC 17.xcdatamodel */;

    这意味着它是当前选择的模型。永远不要删除这一行。只需将文本更改为另一个模型版本即可。

  10. 重新打开 XCode。

回答by RaffAl

My answer is not issue-specific at all but it's quick and works. For those using git. You can just discard unstaged changes.

我的答案根本不是针对特定问题的,但它快速且有效。对于那些使用 git 的人。您可以放弃未暂存的更改。

git stash save --keep-index

Then you can drop that stash with a git stash dropcommand if you like.

然后,git stash drop如果您愿意,您可以使用命令删除该存储。