Xcode 预处理器依赖于环境变量
我有一个配置,我想通过环境变量动态控制预处理器定义的值。
这可能吗?如果是如何在预处理器定义表中设置我想要根据环境变量设置值?
I have a configuration that I'd like to dynamically control a preprocessor defined value through an environment variable.
Is this possible? if it is how do I set in the preprocessor define table that I want to set the value based on the environment variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在项目目标的“构建设置”中,您可以将类似的内容添加到“预处理器宏”字段中:
当然,
USER
变量可以替换为 Xcode 可用的任何环境变量构建系统。要获取这些变量的列表,您可以将运行脚本添加到目标并启用复选标记“在构建日志中显示环境变量”。然后,您可以在代码中使用
DEV_USERNAME
预处理器宏。如果您想将其用作字符串,则可以“字符串化”它:这将为您提供用双引号括起来的用户名。
In the "Build Settings" of a target of your project, you can add something like that to the "Preprocessor Macros" field:
Of course, the
USER
variable can be replaced by any environment variable available to Xcode build system. To get a list of those, you can add a run script to your target and enable the checkmark "Show environment variables in build log."You can then use the
DEV_USERNAME
preprocessor macro in your code. And if you want to use it as a string, you can "stringify" it:This will give you the username surrounded by double quotes.