如何在 Xcode 中定义预处理器符号 [英] How to define a preprocessor symbol in Xcode
问题描述
是否可以通过在 Xcode 项目中设置属性来设置条件编译的符号?
Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project?
我的目标是创建一个对所有文件都可用的符号,而不必使用导入/包含,以便一组公共类可以在某些项目中具有特殊行为.像下面这样,但有我自己的符号.
My aim is to to create a symbol that is available to all files, without having to use import/include, so that a set of common classes can have a special behavior in some projects. Like the following, but with my own symbols.
#if TARGET_IPHONE_SIMULATOR
...
#endif
推荐答案
转到您的目标或项目设置,单击左下角的齿轮图标,然后选择添加用户定义的设置".新设置名称应为 GCC_PREPROCESSOR_DEFINITIONS
,您可以在右侧字段中输入您的定义.
Go to your Target or Project settings, click the Gear icon at the bottom left, and select "Add User-Defined Setting". The new setting name should be GCC_PREPROCESSOR_DEFINITIONS
, and you can type your definitions in the right-hand field.
根据 Steph 的评论,完整的语法是:
Per Steph's comments, the full syntax is:
constant_1=VALUE constant_2=VALUE
请注意,如果您只想#define 一个符号,而不是给它一个值(对于 #ifdef
语句),则不需要 '='s)
Note that you don't need the '='s if you just want to #define a symbol, rather than giving it a value (for #ifdef
statements)
这篇关于如何在 Xcode 中定义预处理器符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!