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

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.

Leave a Comment