如何在Xcode中定义预处理器符号 [英] How to define a preprocessor symbol in Xcode

查看:215
本文介绍了如何在Xcode中定义预处理器符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过在Xcode项目中设置属性来设置用于条件编译的符号?

Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project?

我的目标是创建一个可用于所有文件的符号,而不必使用import/include,以便一组通用类在某些项目中可以具有特殊的行为.类似于以下内容,但带有我自己的符号.

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

推荐答案

转到目标"或项目"设置,单击左下方的Gear图标,然后选择添加用户定义的设置".新的设置名称应为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语句),则不需要

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屋!

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