Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a preprocessor symbol in 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 
like image 891
Steph Thirion Avatar asked Dec 15 '08 02:12

Steph Thirion


People also ask

How to create Preprocessor Macros in Xcode?

After Xcode 8, Apple has added another setting called Active Compilation Conditions where you can add your pre processor macro without the "-D" option and swift will be able to recognize it. Show activity on this post. You need to set swift custom flags to access the pre-macro processors in swift.

What is a preprocessor symbol?

All Preprocessor directives begin with the # (hash) symbol. C++ compilers use the same C preprocessor. The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it.

What is preprocessor in Swift?

This preprocessor macro is used to declare the environment of the application. This macro is used to declare the runtime environment of the application. #if DEBUG print("App is in Debug mode") #else print("App is in production mode")


1 Answers

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.

Per Steph's comments, the full syntax is:

constant_1=VALUE constant_2=VALUE 

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)

like image 104
Ben Gottlieb Avatar answered Sep 16 '22 14:09

Ben Gottlieb