How can I access a user-defined Xcode build setting?

前端 未结 6 900
忘了有多久
忘了有多久 2020-12-13 00:24

If I added a user-defined setting in my build configuration, how can I read that setting in my Objective-C code?

I have two files in my project, debug.plist

6条回答
  •  星月不相逢
    2020-12-13 00:51

    Here's what I did, I'm not 100% sure if this is what you're after:

    1. Go into the build Settings panel and choose the gear icon in the bottom left: add User-Defined Setting
    2. Create your user defined setting, for example:

      MY_LANG -> en_us
      
    3. Then, in the Preprocessor Macro's setting, you can reference that value:

      LANGCODE="$(MY_LANG)"
      

    Now you can refer to LANGCODE in all your source files, and it will be whatever you filled out in your custom build setting. I realize that there's a level of indirection here, but that is intentional in my case: my XCode project contains a bunch of different targets/configurations with their own preprocessor macro's. I don't want to have to go into all of those, just to change the language code. In fact, I define the language code on the project level. I also use MY_LANG in a couple scripts, so just a preprocessor macro wouldn't do. There may be a smarter way, but this works for me.

提交回复
热议问题