将文件夹添加到 Xcode 项目

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

Adding a folder to Xcode project

xcodefile-management

提问by Romejanic

I have a folder full of files on my iPhone app which I want to use, but Xcode will not let me add folders to the bundle, only its files. I can't do this because I want it to be a bit more convenient, so I can reference the folder in my code. So, how do I do this? The compile settings in the build targets won't let me add the folder, only its files.

我的 iPhone 应用程序中有一个装满文件的文件夹,我想使用它,但 Xcode 不允许我将文件夹添加到包中,而只允许添加它的文件。我不能这样做,因为我希望它更方便一些,所以我可以在我的代码中引用该文件夹。那么,我该怎么做呢?构建目标中的编译设置不允许我添加文件夹,只能添加它的文件。

回答by zaph

Drag the source folder to the project "Groups & Files" area, say under the Resources group. In the dialog select "Create Folder References for any added folders". This will create a blue folder and the folder will and it's inter hierarchy will appear in the apps resources. This will automatically create an entry in "Copy Bundle Resources" build phase This is commonly done for image & help files. Any changes made to the folder will also change the files included by Xcode.

将源文件夹拖到项目“组和文件”区域,比如在资源组下。在对话框中选择“为任何添加的文件夹创建文件夹引用”。这将创建一个蓝色文件夹,该文件夹及其内部层次结构将出现在应用程序资源中。这将在“复制捆绑资源”构建阶段自动创建一个条目 这通常用于图像和帮助文件。对文件夹所做的任何更改也将更改 Xcode 包含的文件。

Note the important thing here: the folder must be a Folder Reference (blue folder). If it's a group (yellow folder), delete it and all its contents from your project tree, then re-add as a Folder Reference. Then make sure that's in the Copy Bundle Resources build phase. – cdespinosa

请注意这里的重要事项:文件夹必须是文件夹引用(蓝色文件夹)。如果它是一个组(黄色文件夹),请从项目树中删除它及其所有内容,然后重新添加为文件夹引用。然后确保它处于 Copy Bundle Resources 构建阶段。– cdespinosa