.xcdatamodeld 文件未在 Xcode 中显示数据模型结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15370264/
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
.xcdatamodeld file not showing data model structure in Xcode
提问by Abhinav
I have .xcdatamodeld file in my project but it not opening up into the data model.
我的项目中有 .xcdatamodeld 文件,但它没有打开数据模型。
When I click on the file in the left sidebar in Xcode, it continues to display the contents of the previously selected file instead of displaying the data model. Likewise, when I right click on the file and choose "Open As >", I cannot select to display it as a Data Model—nothing comes up. I checked out the code from the SVN repo and even the filer owner is not able to see it in his workspace.
当我点击 Xcode 左侧边栏中的文件时,它会继续显示之前选择的文件的内容,而不是显示数据模型。同样,当我右键单击文件并选择“打开为 >”时,我无法选择将其显示为数据模型——什么也没有出现。我检查了 SVN 存储库中的代码,甚至文件管理器所有者也无法在他的工作区中看到它。
回答by Duncan Babbage
This is a symptom that I have seen from time to time. In at least one case, this was due Xcode having the wrong path stored in the path
component of the XCVersionGroup
section of the project.pbxproj file, and having an apparently unnecessary additional name
component in that section. It would probably be possible to manually edit this file, but I'm always reluctant to monkey around with the project file directly, and fortunately there's an easier way.
这是我不时看到的症状。至少在一种情况下,这是由于 Xcode在 project.pbxproj 文件部分的path
组件中存储了错误的路径XCVersionGroup
,并且name
在该部分中有一个明显不必要的附加组件。手动编辑这个文件可能是可能的,但我总是不愿意直接修改项目文件,幸运的是有一个更简单的方法。
- Navigate to your .xcdatamodeld file in the Finder. The easiest way to do this is Right click/Ctrl-click on the .xcdatamodeld file and select "Show in Finder".
- Drag the file from the Finder and drop it immediately above or below the current reference to the .xcdatamodeld in the Project Navigator in your Xcode project.
- Click OK to accept the import, ensuring that you are adding it to the correct targets. (Which targets are correct will depend on your project.)
- You will now have two references to the same file in your Project Navigator. Clicking on eitherof them will now bring up the desired data model structure.
- Remove the duplicate reference to the model file. Click on one of the file references (doesn't appear to matter which, though it may be better to remove the old one) and press Delete.
- In the resulting confirmation dialog, be sure to select "Remove Reference" only, and do NOT move the file to the trash. (The two references point to only one actual file in the file system. Moving to trash would thus trash the only copy.)
- 在 Finder 中导航到您的 .xcdatamodeld 文件。最简单的方法是右键单击/按住 Ctrl 键单击 .xcdatamodeld 文件,然后选择“在 Finder 中显示”。
- 将文件从 Finder 中拖放到 Xcode 项目的 Project Navigator 中对 .xcdatamodeld 的当前引用的正上方或下方。
- 单击“确定”接受导入,确保将其添加到正确的目标。(哪些目标是正确的取决于您的项目。)
- 现在,您的项目导航器中将有两个对同一文件的引用。单击其中任何一个现在将显示所需的数据模型结构。
- 删除对模型文件的重复引用。单击其中一个文件引用(似乎无关紧要,尽管删除旧的可能更好),然后按 Delete。
- 在出现的确认对话框中,请确保仅选择“删除引用”,不要将文件移至垃圾箱。(这两个引用仅指向文件系统中的一个实际文件。因此,移至垃圾箱将删除唯一的副本。)
You're now left with just one reference to the data model, and it works.
您现在只剩下对数据模型的一个引用,并且它可以工作。
One thing that appears to trigger this bug is moving the .xcdatamodeld file in the file structure on disk. Even after correctly re-associating the file with the new location (i.e., it no longer appears in red in the sidebar), the one section of the Project file mentioned above is not correctly updated, and thus the file is not treated fully correctly as an Xcode Data Model file.
似乎触发此错误的一件事是在磁盘上的文件结构中移动 .xcdatamodeld 文件。即使正确地将文件与新位置重新关联(即,它不再出现在侧栏中的红色),上述项目文件的一部分没有正确更新,因此该文件没有被完全正确地视为一个 Xcode 数据模型文件。
回答by Jeremy
I encountered the same issue in Xcode 6.3
我在 Xcode 6.3 中遇到了同样的问题
The only solution that worked for me was to move the .xcdatamodeld file out of my 'Resources' folder and into the project root folderin the Xcode project explorer (location on the filesystem doesn't matter)
唯一对我有用的解决方案是将 .xcdatamodeld 文件从我的“资源”文件夹中移到Xcode 项目资源管理器中的项目根文件夹中(文件系统上的位置无关紧要)
I'm still not sure why, just moving the location of the file in the project structure causes it to not show up at all when clicked.. but apparently, at least in my setup, it doesn't like living in the Resources folder..
我仍然不确定为什么,只是在项目结构中移动文件的位置会导致它在单击时根本不显示......但显然,至少在我的设置中,它不喜欢住在 Resources 文件夹中..
回答by Kevin Delord
For some dark reasons, sometimes Xcode needs the xcdatamodeldfiel to be in the root folder. I wrote an answer herethat explain how to do this, but also a workaround to have this file where ever you would like to.
由于一些黑暗的原因,有时 Xcode 需要 xcdatamodel d字段位于根文件夹中。我在这里写了一个答案,解释了如何做到这一点,但也是一个解决方法,可以在任何你想要的地方放置这个文件。
Cheers!
干杯!
回答by Adam
The .xcdatamodeld
file is a package. It contains .xcdatamodel
packages, one for each version of the model. Inside every .xcdatamodel
there is a contents
file, which is an XMLwith entities description. To see what is inside your packages, right-click them in Finder and choose Show Package Contentsoption.
该.xcdatamodeld
文件是一个包。它包含.xcdatamodel
包,每个版本的模型一个。每个.xcdatamodel
里面都有一个contents
文件,它是一个带有实体描述的XML。要查看包中的内容,请在 Finder 中右键单击它们并选择“显示包内容”选项。
Perhaps you didn't add the contents
file into your repository. This way you will not be able to see your model when you create a brand new working copy from it.
也许您没有将该contents
文件添加到您的存储库中。这样,当您从中创建全新的工作副本时,您将无法看到您的模型。
回答by Jean Le Moignan
I was victim of this problem today on Xcode8.
我今天在 Xcode8 上遇到了这个问题。
I solved it simply by placing the xcdatamodeld file outside any group in the Project navigator (left pane). As soon as I move it into a group, I can't open the little guy anymore.
我只是通过将 xcdatamodeld 文件放在项目导航器(左窗格)中的任何组之外来解决它。一搬进群里,小家伙就打不开了。
回答by SteveC
I had a similar problem with Xcode 7.3.1.
我在 Xcode 7.3.1 上遇到了类似的问题。
It turned out to be related to the way the data model packages were configured.
结果证明这与数据模型包的配置方式有关。
I discovered that there was one embedded model package nested inside another. Let's say a top level data model called FolderNodes.xcdatamodeld containing another with exactly the same name ... FolderNodes.xcdatamodeld. Inside FolderNodes.xcdatamodeld is the actual contents file that has the model info.
我发现有一个嵌入的模型包嵌套在另一个中。假设一个名为 FolderNodes.xcdatamodeld 的顶级数据模型包含另一个具有完全相同名称的... FolderNodes.xcdatamodeld。FolderNodes.xcdatamodeld 内部是包含模型信息的实际内容文件。
The solution for me was to drag the embedded package FolderNodes.xcdatamodeld ( number 2) into the Xcode project and NOT its enclosing folder.
我的解决方案是将嵌入式包 FolderNodes.xcdatamodeld(编号 2)拖到 Xcode 项目中,而不是它的封闭文件夹中。
Apple uses the package for versioning but I think the logic associated with moving the data model file somehow breaks the original package creating a redundant wrapper.
Apple 使用该包进行版本控制,但我认为与移动数据模型文件相关的逻辑以某种方式破坏了原始包,从而创建了一个冗余包装器。
回答by NoilPaw
Make sure your Version Editor
is not active.
确保您Version Editor
未处于活动状态。
Having the Version Editor
open results in the xml code to be displayed instead of the Data Model
. You will also not be able to choose Data Model
in the context menu of the xcdatamodeld file within the Project Navigator
.
在Version Editor
要显示的 xml 代码中打开结果而不是Data Model
. 您也将无法Data Model
在 .xcdatamodeld 文件的上下文菜单中进行选择Project Navigator
。
回答by Mehul Parmar
Happens on XCode 8.3 as well.
也发生在 XCode 8.3 上。
For me, moving the physical file to a different folder, then deleting the original reference, then adding it back to same place and establishing the reference again does the job.
对我来说,将物理文件移动到不同的文件夹,然后删除原始引用,然后将其添加回同一位置并再次建立引用即可完成这项工作。