Swift: Conditional Compilation
Debug spew is a great support mechanism for tracking workflow of your code and to augment debugging. However, leaving that support within your code is not just a poor decor for code stylists, it can also lead to security issues and occasionally to App Review Rejections. As of Swift 2.1, if all you need is just check whether the code is built with debug or release configuration, you may use the built-in functions: _isDebugAssertConfiguration() (true when optimization is set to -Onone ) _isReleaseAssertConfiguration() (true when optimization is set to -O ) _isFastAssertConfiguration() (true when optimization is set to -Ounchecked ) It would be used as the following example: func obtain() -> AbstractThing { if _isDebugAssertConfiguration () { return DecoratedThingWithDebugInformation(Thing()) } else { return Thing() } } Compared with preprocessor macros, ✓ You don’t need to define a custom -D DEBUG flag to use it ~ It is actually defi