Xcode 组织文件和文件夹(核心数据模型对象 - iPhone)

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

Xcode organising files and folders (core data model objects - iPhone)

iphoneobjective-cxcodecore-data

提问by Urizen

I am developing for the iPhone and the prevailing advice on auto-generating files from entities, when using Core Data, is to select the *.xcdatamodel file and the create the new file(s) etc. This creates the *.m and *.h files in the Resources directory. These are then moved to the Classes directory or a subdirectory of Classes.

我正在为 iPhone 开发,在使用 Core Data 时,关于从实体自动生成文件的普遍建议是选择 *.xcdatamodel 文件并创建新文件等。这将创建 *.m 和 *资源目录中的 .h 文件。然后将它们移动到 Classes 目录或 Classes 的子目录。

However, when viewing my github repository I notice that all of the model files which have been auto-generated in the above mentioned way are present on the root of the project folder (as if they were a resource).

但是,在查看我的 github 存储库时,我注意到以上述方式自动生成的所有模型文件都存在于项目文件夹的根目录中(就好像它们是资源一样)。

The underlying file structure may or may not matter (I'm unsure on this point) but I would like to make my repository less disorganised. I can see entropy taking over as the project gets much bigger and there are more files to contend with.

底层文件结构可能重要也可能无关紧要(我不确定这一点)但我想让我的存储库不那么杂乱无章。随着项目变得越来越大并且有更多的文件需要处理,我可以看到熵正在接管。

My question is therefore: is there a way to organise the underlying file structure without messing up the project settings or the way github sees the project?

因此,我的问题是:有没有一种方法可以在不弄乱项目设置或 github 看待项目的方式的情况下组织底层文件结构?

I hope the above isn't unclear and I look forward to your replies.

我希望以上没有不清楚,我期待着您的回复。

回答by Matt B.

Yes, this is possible. The Xcode groups (the yellow "folders," like your Resources) are completely independent of the file system - they don't directly represent directories. If you select a group and go to File -> Get Info, you can select the base path for that group of files. You can create and select a new folder through the file chooser there.

是的,这是可能的。Xcode 组(黄色的“文件夹”,如您的资源)完全独立于文件系统——它们不直接代表目录。如果您选择一个组并转到文件 -> 获取信息,您可以选择该组文件的基本路径。您可以通过那里的文件选择器创建和选择一个新文件夹。

Once you do this, all the files in that group will go red - Xcode can no longer find them through the new path. Use the Finder (or Git) to move them into your new directory, and all should be well.

执行此操作后,该组中的所有文件都将变为红色 - Xcode 无法再通过新路径找到它们。使用 Finder(或 Git)将它们移动到您的新目录中,一切都应该没问题。

Xcode defaults to placing new Managed Object classes in the folder that the model is in, so new resources will get placed there automatically.

Xcode 默认将新的托管对象类放置在模型所在的文件夹中,因此新资源将自动放置在那里。

As a sidenote, I highly recommend Rentzsch's Mogeneratorto handle Managed Object class creation. It divorces Xcode's auto-generated code from your custom code, and then automagically regenerates the template code every time your model changes (without losing your own code).

作为旁注,我强烈推荐 Rentzsch 的Mogenerator来处理托管对象类的创建。它将 Xcode 自动生成的代码与您的自定义代码分离,然后在每次模型更改时自动重新生成模板代码(不会丢失您自己的代码)。