问题描述
我有一个项目,我分成两个目标。原始的单目标项目使用了许多定义命令,但是我现在需要这些值,这取决于我正在构建的目标。
I have a project I am splitting into two targets. The original single-target project uses a number of define commands, however I need these values to now be different depending on which target I am building.
什么是正确的方法去做?我应该使用在AppDelegate上声明的NStrings吗?或者我可以在设置#defines时使用#if语句吗?
What's the correct way to do that? Should I be using NStrings declared on the AppDelegate? Or can I use a #if statement when settings the #defines?
任何帮助,非常感谢。
Any help, much appreciated.
推荐答案
一种方法是这样的:
#if defined(MON_TARGET_A)
#define MON_TARGET_NAME "App A"
#elif defined(MON_TARGET_B)
#define MON_TARGET_NAME "App B"
#else
#error "which target are you building?"
#endif
然后添加 MON_TARGET_A
或 MON_TARGET_B
到你的目标的预处理器设置。
Then add MON_TARGET_A
or MON_TARGET_B
to your target's preprocessor settings.
通常,你将使用 GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
而不是 GCC_PREPROCESSOR_DEFINITIONS
因为后者可以阻止共享PCH标头。
Usually, you'll use GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
and not GCC_PREPROCESSOR_DEFINITIONS
because the latter can prevent sharing of PCH headers.
要添加这个,转到:
- 项目导航器 - >项目 - >目标 - >构建设置
然后将 GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
放入搜索字段并将其值设置为: MON_TARGET_A $(继承)
then drop GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
into the search field and set its value to something like: MON_TARGET_A $(inherited)
这篇关于如何为我的两个不同目标指定#define命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!