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
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.
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.
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")
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With