Xcode preprocessor dependent on environment variable

前端 未结 1 2334
囚心锁ツ
囚心锁ツ 2021-02-20 18:20

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

1条回答
  •  爱一瞬间的悲伤
    2021-02-20 18:32

    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.

    0 讨论(0)
提交回复
热议问题