如何访问用户定义的Xcode构建设置? [英] How can I access a user-defined Xcode build setting?

查看:126
本文介绍了如何访问用户定义的Xcode构建设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在构建配置中添加了用户定义的设置,如何在我的Objective-C代码中读取该设置?

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

我的项目中有两个文件,分别为debug.plistrelease.plist.我希望我的MainApp.m文件根据正在运行的内部配置读取这些文件之一.我在调试"和发布"配置中都设置了一个名为文件名"的用户定义设置,以指向适当的文件.但是我不知道我的MainApp.m文件如何从当前运行的配置中读取文件名变量.

I have two files in my project, debug.plist and release.plist. I want my MainApp.m file to read one of these files based on which build configuration is running. I set up a user-defined setting named "filename" in both the Debug and Release configurations to point to the appropriate file. But I don't know how my MainApp.m file can read the filename variable from the current running configuration.

推荐答案

这是我所做的,我不确定100%是否是您要的:

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

  1. 进入构建设置面板,然后选择左下角的齿轮图标:添加用户定义的设置
  2. 创建用户定义的设置,例如:

  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

  • 然后,在Preprocessor Macro的设置中,您可以引用该值:

  • Then, in the Preprocessor Macro's setting, you can reference that value:

    LANGCODE="$(MY_LANG)"
    

  • 现在,您可以在所有源文件中引用LANGCODE,它将成为您在自定义生成设置中填写的内容.我意识到这里有一个间接级别,但是在我的情况下,这是有意的:我的XCode项目包含一堆不同的目标/配置以及它们自己的预处理器宏.我不想去研究所有这些,只是为了更改语言代码.实际上,我在项目级别定义了语言代码.我还在几个脚本中使用了MY_LANG,所以 just 预处理器宏是不会做的.也许有一种更聪明的方法,但这对我有用.

    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.

    这篇关于如何访问用户定义的Xcode构建设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆