Is there some kind of #if not
for a swift flag ?
I know
#if myFlag #else #endif
could work, but it ain't pretty if there is nothing between if
and else
.
The Swift compiler does not include a preprocessor. Instead, it takes advantage of compile-time attributes, build configurations, and language features to accomplish the same functionality. For this reason, preprocessor directives are not imported in Swift.
Active Compilation Conditions is a new build setting for passing conditional compilation flags to the Swift compiler. Each element of the value of this setting passes to swiftc prefixed with -D , in the same way that elements of Preprocessor Macros pass to clang with the same prefix. (
To do that, goto Project (not target)→Build settings → Swift Compiler → Custom flags → Other swift flags section and edit the different configuration flags. Add the flags using the syntax “ -D <flag_name>”. NOTE: if you are not seeing Other swift flags section, you will be in the basic build settings mode.
Macros in Swift programming are generally the block of code available to the developer as a single statement. A single block of code consists of a large number of statements or instructions. Hence making the development less tedious.
I wasn't trying enough, I found out
#if !myFlag #endif
works well !
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