Xcode 预处理器依赖于环境变量

发布于 2024-12-29 22:09:28 字数 78 浏览 5 评论 0原文

我有一个配置,我想通过环境变量动态控制预处理器定义的值。

这可能吗?如果是如何在预处理器定义表中设置我想要根据环境变量设置值?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2025-01-05 22:09:28

在项目目标的“构建设置”中,您可以将类似的内容添加到“预处理器宏”字段中:

DEV_USERNAME="${USER}"

当然,USER 变量可以替换为 Xcode 可用的任何环境变量构建系统。要获取这些变量的列表,您可以将运行脚本添加到目标并启用复选标记“在构建日志中显示环境变量”。

然后,您可以在代码中使用 DEV_USERNAME 预处理器宏。如果您想将其用作字符串,则可以“字符串化”它:

#define xstr(s) str(s)
#define str(s) #s

xstr(DEV_USERNAME)

这将为您提供用双引号括起来的用户名。

In the "Build Settings" of a target of your project, you can add something like that to the "Preprocessor Macros" field:

DEV_USERNAME="${USER}"

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:

#define xstr(s) str(s)
#define str(s) #s

xstr(DEV_USERNAME)

This will give you the username surrounded by double quotes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文