Xcode preprocessor dependent on environment variable

冷暖自知 提交于 2019-12-21 07:57:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9088380/xcode-preprocessor-dependent-on-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!