xcode 创建 Plist 并将其复制到资源包中的构建阶段

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

Build phase that create a Plist and copy it in resource bundle

xcode

提问by Luca Bernardi

I've made a ruby script that generate a Plist from data in other format (This script is inside the xcode's project folder).

我制作了一个 ruby​​ 脚本,它从其他格式的数据生成一个 Plist(这个脚本在 xcode 的项目文件夹中)。

I've made a custom run script build phase that call my script:

我制作了一个调用我的脚本的自定义运行脚本构建阶段:

echo "Running xls Plister"
cd ${PROJECT_DIR}/plistr
ruby plistr.rb
scriptExitStatus=$?
echo "DONE with script: (exitStatus=${scriptExitStatus})"
exit "${scriptExitStatus}"

This script output the plist in the following folder ${PROJECT_DIR}/plistr/output/data.plist

此脚本输出以下文件夹中的 plist ${PROJECT_DIR}/plistr/output/data.plist

What I can't figure out is how to copy this in the Bundle resource so i can access it with something like this:

我不知道如何在 Bundle 资源中复制它,以便我可以使用以下内容访问它:

[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];

EDIT: my actual workaround is to run the script as first build step and manually add the reference to the generated plist in "Copy Bundle Resources"

编辑:我的实际解决方法是将脚本作为第一个构建步骤运行,并在“复制捆绑资源”中手动添加对生成的 plist 的引用

回答by Nick Weaver

You can copy a file to the bundle this way:

您可以通过以下方式将文件复制到包中:

cp /tmp/foo.txt ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

Please notice, copying the info.plistto the bundle is not recommended, it will also produce a warning if copied with the Copy Bundle Resources build phase.

请注意,不建议将info.plist复制到包中,如果在复制包资源构建阶段复制它也会产生警告。

Look at this official statement.

看看这个官方声明