资源文件未随 Xcode 5 更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19124083/
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
Resource files not updating with Xcode 5
提问by Kyle
I have some binary files with a proprietary extension that don't get updated in a build when I compile. In previous versions of Xcode with this same project, it would detect the file was changed, and rarely would I have to perform a 'Clean' as I have to do with this version. Of course this is consuming a lot more time -- I would appreciate it if someone could let me know what's changed with Xcode 5 and/or what I could do about this.
我有一些带有专有扩展名的二进制文件,在编译时不会在构建中更新。在具有相同项目的先前版本的 Xcode 中,它会检测到文件已更改,并且我很少需要像这个版本那样执行“清理”。当然,这会消耗更多时间——如果有人能让我知道 Xcode 5 发生了什么变化和/或我可以对此做些什么,我将不胜感激。
I didn't include any project specifics because it's really just a proprietary binary file with a custom extension in a resource folder, which, used to update automatically upon it being changed since last compile. If you need any specific project settings I would be glad to offer it.
我没有包含任何项目细节,因为它实际上只是一个专有的二进制文件,在资源文件夹中带有自定义扩展名,自上次编译以来,它用于在更改时自动更新。如果您需要任何特定的项目设置,我很乐意提供。
It's using the sort of 'blue' resource folder that is a reference to the folder it's in, and isn't just copied into the project directory. I apologize since I forget what this particular resource folder type is called (I'm guessing Reference).
它使用一种“蓝色”资源文件夹,它是对其所在文件夹的引用,而不仅仅是复制到项目目录中。我很抱歉,因为我忘记了这个特定资源文件夹类型的名称(我猜是参考)。
Version: Xcode 5 (5A1413)
版本:Xcode 5 (5A1413)
UPDATE:
更新:
This only happens when I'm referencing a file that I modify programmatically with fopen,fwrite,etc, and upon using a file editor in OSX to resave the file (without really changing it) Xcode will then see it as changed.
这仅在我引用我使用 fopen、fwrite 等以编程方式修改的文件时发生,并且在 OSX 中使用文件编辑器重新保存文件(没有真正更改它)时,Xcode 将看到它已更改。
I'm now looking into FSEvents to see if this underlying API is something I need to use, although I'm not exactly sure how to set flags with this just yet.
我现在正在研究 FSEvents,看看这个底层 API 是否是我需要使用的东西,尽管我还不确定如何使用它设置标志。
UPDATE:
更新:
Well, just as a simple test, I take the same file and resave it via:
好吧,作为一个简单的测试,我使用相同的文件并通过以下方式重新保存它:
NSData* data = [[NSData alloc] initWithContentsOfFile: @"/location/file.dat"];
[data writeToFile:@"/location/file.dat" atomically:YES];
NSData* data = [[NSData alloc] initWithContentsOfFile: @"/location/file.dat"];
[data writeToFile:@"/location/file.dat" atomically:YES];
Sure enough, after I call that and then run the app that uses the resource, it is updated via Xcode during the build. So it would seem that Xcode 5 relies on some special flags not set by the standard io functions. At this point I can either patch what I've got with that 2 line thing or figure out what the flagging mechanism is, and how to write to it. (FSEvents? I don't see a writing mechanism there..)
果然,在我调用它然后运行使用该资源的应用程序后,它在构建期间通过 Xcode 更新。因此,Xcode 5 似乎依赖于标准 io 函数未设置的一些特殊标志。在这一点上,我可以用那 2 行的东西修补我所拥有的东西,或者弄清楚标记机制是什么,以及如何写入它。(FSEvents?我在那里看不到写入机制..)
采纳答案by worstoo
I was also running into problems. Everything was fine before Xcode 5, and my referenced resources folder would copy pretty dependably. However, after updating, no matter what I did to an individual file (touch it, delete and re-copy it, etc.), nothing triggered Xcode to scoop it up again.
我也遇到了问题。在 Xcode 5 之前一切都很好,我引用的资源文件夹会非常可靠地复制。但是,更新后,无论我对单个文件做了什么(触摸它、删除并重新复制它等),都没有触发 Xcode 再次抓取它。
However, I now modify the last write time on the referenced folder during my build step, and now it's contents seem to be copying correctly again. I Hope that helps you too.
但是,我现在在构建步骤中修改了引用文件夹的上次写入时间,现在它的内容似乎再次正确复制。我希望这对你也有帮助。
I am using custom tools, but I'm sure a build script can do the same. My guess is that Xcode tries to optimize the dependency step, and checks the folder's last access/write times before diving into it.
我正在使用自定义工具,但我确信构建脚本可以做到这一点。我的猜测是 Xcode 尝试优化依赖项步骤,并在深入研究之前检查文件夹的上次访问/写入时间。
回答by Paul Slocum
I had the same problem. I set up an Xcode build-phase script to touch the root resource folder, and it works now. I found the instructions hereand they are as follows (see link for more detail):
我有同样的问题。我设置了一个 Xcode 构建阶段脚本来访问根资源文件夹,现在它可以工作了。我在这里找到了说明,它们如下(有关更多详细信息,请参阅链接):
1) Add your single resource directory (named anything but ‘Resources') to your project in the Resources section as a blue ‘Folder Reference'
1) 将您的单个资源目录(命名为“Resources”以外的任何名称)作为蓝色“文件夹引用”添加到“资源”部分中的项目中
2) Right click on your app target, select Add->New Build Phase->New Run Script Build Phase
2) 右键单击您的应用程序目标,选择 Add->New Build Phase->New Run Script Build Phase
3) In the resulting ‘Info' window, change the shell to /bin/tcsh and copy and past the script below into the ‘Script' text view.
3) 在出现的“信息”窗口中,将 shell 更改为 /bin/tcsh 并将下面的脚本复制并粘贴到“脚本”文本视图中。
Script:
脚本:
touch -cm ${SRCROOT}/../../YourResourceFolder
(Also, you may need to know how to find "Build Phases" in Xcode 5)
(此外,您可能需要知道如何在 Xcode 5 中找到“构建阶段”)
回答by Nitin
well a simpler way would be to just touch the folder from your shell or term. e.g. on your terminal just run touch -cm PATH_TO_FOLDER_UNDER_RESOURCES
一个更简单的方法是从你的 shell 或术语中触摸文件夹。例如在你的终端上运行 touch -cm PATH_TO_FOLDER_UNDER_RESOURCES
PATH_TO_FOLDER_UNDER_RESOURCES is actual path to the folder under resource folders which contains the files.
PATH_TO_FOLDER_UNDER_RESOURCES 是包含文件的资源文件夹下文件夹的实际路径。
Since changing your files do not necessarily change the timestamp of the folder and Xcode looks into the timestamp of the containing folder.
由于更改文件不一定会更改文件夹的时间戳,因此 Xcode 会查看包含文件夹的时间戳。
回答by poordeveloper
I had the same issue with xcode5, I need to update javascript frequently. I had to clean and then build, it took long time because my project had many source files. Later I tried to delete the app (choose "move to trash" rather than "delete reference") and then build, it was quite fast, but I had to restart xcode so that app can appear in the project again.
我在 xcode5 上遇到了同样的问题,我需要经常更新 javascript。我必须清理然后构建,这需要很长时间,因为我的项目有很多源文件。后来我尝试删除该应用程序(选择“移至垃圾箱”而不是“删除引用”)然后构建,速度非常快,但我不得不重新启动 xcode 以便应用程序可以再次出现在项目中。