In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project
In Swift you can still use the "#if/#else/#endif" preprocessor macros (although more constrained), as per Apple docs. Here's an example:
#if DEBUG
let a = 2
#else
let a = 3
#endif
Now, you must set the "DEBUG" symbol elsewhere, though. Set it in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line. You add the DEBUG symbol with the -D DEBUG
entry.
(Build Settings -> Swift Compiler - Custom Flags)
As usual, you can set a different value when in Debug or when in Release.
I tested it in real code; it doesn't seem to be recognized in a playground.
Conditional exclusion of code in Swift
The issue was about replicating the configuration in the Other Swift Flags file in the form
-D option
Apparently Swift ignores the flags in the preprocessor field. Now it accepts ||, && and ! without any problem with syntax:
#if option || !option2
......
#elseif option3
......
#endif
Xcode 8 and Preprocessor Macros
It was an actual bug in XCode 8. With XCode 9 (as of today, Sep 2017 beta 6), it is finally resolved.
Swift Xcode conditional precompilation
Your flag formatting is correct except that there shouldn't be a space between -D
and FEATURE_A_ENABLED
. It should be -DFEATURE_A_ENABLED
.
Related Topics
Is There a Good Charting Library For Iphone
Proper Use of Beginbackgroundtaskwithexpirationhandler
Detect If the App Was Launched/Opened from a Push Notification
How to Scale Down a Uiimage and Make It Crispy/Sharp At the Same Time Instead of Blurry
Are There APIs For Custom Vibrations in Ios
How Would I Tint an Image Programmatically on Ios
Passing Parameters to Addtarget:Action:Forcontrolevents
iPhone Reboot Programmatically
How to Implement Method Swizzling Swift 3.0
How Add Separator to String at Every N Characters in Swift
How to Know When Uitableview Did Scroll to Bottom in Iphone
Detect When an iOS App Is Launched For the First Time
Shouldautorotatetointerfaceorientation Not Being Called in iOS 6
Customize Uitableview Header Section
Basic Example For Sharing Text or Image With Uiactivityviewcontroller in Swift