Xcode 构建和资源文件夹

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

Xcode building and resources folders

iphonexcodemacosresources

提问by Michael Waterfall

I have several resources in my iPhone app and when they get compiled they all get added to the root of the resources folder in the app regardless of the Xcode grouping structure. This is fine for most things, however there is a set of files that I need to have structured in folder in the app's resources folder.

我的 iPhone 应用程序中有几个资源,当它们被编译时,无论 Xcode 分组结构如何,它们都会被添加到应用程序中资源文件夹的根目录中。这对大多数事情来说都很好,但是我需要在应用程序资源文件夹中的文件夹中构建一组文件。

At the moment, I have added my folders to Xcode using "Add Existing Files... -> Create Folder References for Added Folders". This is fine and the folder icons in Xcode are blue instead of yellow. My problem is that Xcode is not noticing and new or changed files within those folders and hence when I build my project, none of the new or changed images are in the target app's resources. The only way I can get it to work is to do a clean, and then build, which is quite annoying as I'm making changes and re-compiling maybe a few times a minute sometimes!

目前,我已使用“添加现有文件...-> 为添加的文件夹创建文件夹引用”将我的文件夹添加到 Xcode。这很好,Xcode 中的文件夹图标是蓝色而不是黄色。我的问题是 Xcode 没有注意到这些文件夹中的新文件或更改的文件,因此当我构建我的项目时,目标应用程序的资源中没有任何新的或更改的图像。我可以让它工作的唯一方法是做一个清理,然后构建,这很烦人,因为我正在进行更改并有时可能每分钟重新编译几次!

My folder structure in my resources that I want kept on in the app consists of several nested files and folder.

我希望在应用程序中保留的资源中的文件夹结构由多个嵌套文件和文件夹组成。

Is there some way to get Xcode to recognise all the files and folders that have changed or are new?

有什么方法可以让 Xcode 识别所有已更改或新的文件和文件夹?

Thanks,

谢谢,

Mike

麦克风

采纳答案by Peter Hosey

My problem is that Xcode is not noticing and new or changed files within those folders and hence when I build my project, none of the new or changed images are in the target app's resources.

我的问题是 Xcode 没有注意到这些文件夹中的新文件或更改的文件,因此当我构建我的项目时,目标应用程序的资源中没有任何新的或更改的图像。

This is a long-standing bug; it's bitten me many times while working on Adium. Please file it in RadarWeb. And thanks for the reminder; I've filed my own bug report as x-radar://problem/7232149 (visible to the public in OpenRadar). You should mention this bug number in your own bug report.

这是一个长期存在的错误;在 Adium 上工作时它被我咬了很多次。请在RadarWeb归档。并感谢您的提醒;我已将自己的错误报告提交为 x-radar://problem/7232149(在 OpenRadar 中对公众可见)。您应该在自己的错误报告中提及此错误编号。

As a workaround, you can right-click on the folder reference and choose “Touch” to tell Xcode that the folder has changed.

作为一种解决方法,您可以右键单击文件夹引用并选择“触摸”以告诉 Xcode 该文件夹已更改。

回答by Cristi B?lu??

i had your first problem myself today and i found this great article, which speaks about the second problem also: http://majicjungle.com/blog/?p=123

今天我自己遇到了你的第一个问题,我发现了这篇很棒的文章,它也谈到了第二个问题:http: //majicjungle.com/blog/?p=123

回答by Dennis Mattingly

I just got bitten by this bug too. The answers already given here were a great help.

我也刚被这个虫子咬了。这里已经给出的答案有很大帮助。

I found the answer in this other thread useful too, but I'm not sure if it is actually a safe thing to do (it seems to generate a new AppId or something):

我发现另一个线程中的答案也很有用,但我不确定这是否真的是一件安全的事情(它似乎生成了一个新的 AppId 或其他东西):

iphone simulator resources not updating

iphone模拟器资源没有更新

These are my personal notes I made to workaround it.

这些是我为解决这个问题所做的个人笔记。

1) Open the project in Xcode
2) Right-click the folder reference (BLUE folder) in the navigator
   at its root and pick "Remove Reference"
3) Close Xcode all the way
4a) Warning, this step might cause other problems in your project.
4b) Open the folder browser / Finder
4c) Navigate to: /users/USERNAME/Library/Application Support/
            /iPhone Simulator/version/Applications/THISPROJFOLDER
4d) Delete this whole THISPROJFOLDER. The name of the folder may be all
    numbers, but this clears the Xcode "Cache" so it will rebuild things
5) Find the actual folder where you store your pictures that were referenced,
   and move the folder elsewhere and rename it.
6) Now open Xcode
7) In Xcode, select Product -> Clean. It should clean successfully.
8) Now run the program through Xcode. It should run, but (hopefully) crash or
   otherwise fail because it doesn't detect the resource files you removed.
9) Now go standard Xcode usage and add the files back to the folder you want,
   and add a reference to that folder in the Xcode navigator. Run the program
   again, and it should detect the UPDATED PDFfiles/Imagefiles.

EDIT: Okay, I followed the "answer" instructions from Peter Hosey's post above, and that works too. Probably better than my solution here, because my step 4 (required) seems to regen an app key or something.

编辑:好的,我按照上面 Peter Hosey 帖子中的“答案”说明进行操作,这也有效。可能比我在这里的解决方案更好,因为我的第 4 步(必需)似乎重新生成了一个应用程序密钥或其他东西。

So here's how I fixed it in Xcode 4.0 following Peter's post:

下面是我在 Xcode 4.0 中按照 Peter 的帖子修复它的方法:

 1) Open your project in Xcode
 2) Select the main project root item in the Navigator
 3) Select "Build Phases" in the main pane
 4) Select "Add Build Phase" button -> "Add Run Script"
 5) Reposition he "Run Script" entry bar in the screen,
    and move it to just-before the Copy Bundle Resources area
 6) Edit the run-script you just added in the main pane:
    : Set Shell to: /bin/sh (its the default, or try /bin/tsch)
    : Set the script line to: touch -cm ${SRCROOT}/MyDocs
    (Set it to your folder root area, matching the Blue Folder
     area in your Navigator)
 7) Save it all and select "Product -> Clean" to clean project

回答by coneybeare

if you want to maintain a directory structure, it is best to do so in the documents directory. On your apps initial launch, copy over the files from the bundle to the documents directory in the hierarchy you prefer.

如果要维护目录结构,最好在文档目录中进行。在您的应用程序首次启动时,将文件从捆绑包复制到您喜欢的层次结构中的文档目录。

EDIT: after clarification, it seems that you probably just need to add some header search paths to your project. Open the targets info pane, go to the build section, and add your structures root folder to the header search paths list. Check recursive and you should be better

编辑:澄清后,似乎您可能只需要向项目添加一些标题搜索路径。打开目标信息窗格,转到构建部分,并将您的结构根文件夹添加到标题搜索路径列表中。检查递归,你应该更好