将文件从脚本添加到 Xcode 项目? [英] Add files to an Xcode project from a script?

查看:69
本文介绍了将文件从脚本添加到 Xcode 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用一些脚本来生成我作为资源包含在 Xcode 中的文件.问题是我正在运行脚本,然后从项目中删除,然后重新添加到项目中.必须有办法自动执行最后一步,以便脚本可以生成文件并自动将它们添加到我的 xcode 项目中.

Right now I'm using a few scripts to generate files that I'm including as resources in Xcode. The thing is I'm running the script, then deleting from the project, then adding back into the project. There must be a way to automate this last step, so that the script can generate the files and automatically add them into the xcode project for me.

我正在使用 bash,但任何语言示例都会有所帮助.

I'm using bash but any language examples would help.

谢谢,安德鲁

推荐答案

这可以通过向您的应用程序添加一个新的构建阶段来完成.

This can be done by adding a new build phase to your application.

  1. 在您的 Xcode 项目浏览器中,找到您的应用程序的目标,并将其展开以显示所有构建阶段.

  1. In your Xcode project browser, find the target for your application, and expand it to show all of the build phases.

添加一个新的"运行脚本"构建阶段到您的目标.最简单的方法是右键单击目标并选择添加/新建构建阶段/新建运行脚本构建阶段"

Add a new "run script" build phase to your target. The easiest way is to right-click on the target and choose "Add/New Build Phase/New Run Script Build Phase"

添加新的构建阶段应该会打开一个检查器窗口.在这个窗口中,您可以输入整个 shell 脚本,或者只是一个命令行来运行脚本.

Adding the new build phase should bring up an inspector window. In this window, you can enter the entire shell script, or simply a command line to run the script.

最重要的是:在检查器窗口的底部,您可以指定输入文件和输出文件.指定输入文件会自动设置依赖项(只有在修改了某些输入文件时才会执行 shell 脚本).指定输出文件会自动将依赖关系传播到这些文件.当你的 shell 脚本运行时,Xcode 知道它需要处理那些 shell 脚本修改过的文件.

Here's the gold: At the bottom of the inspector window you can specify input files and output files. Specifying input files sets up dependencies automatically (the shell script will only be executed if some of the input files have been modified). Specifying output files automatically propagates the dependencies to those files. When your shell script is run, Xcode knows that it needs to deal with those files that the shell script has modified.

确保将您的新构建阶段拖到阶段列表的顶部,如下面的屏幕截图所示.如果您需要将这些资源文件包含在包中,那么顺序将很重要.

Be sure to drag your new build phase up to the top of the list of phases as shown in the screenshot below. The order will be important if you need those resource files to be included in the bundle.

保存、构建、提交到存储库、要求加薪、呼吸新鲜空气并度过美好的一天!:)

Save, build, commit to the repository, ask for a raise, get some fresh air and have a nice day! :)

这篇关于将文件从脚本添加到 Xcode 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆