ARTICLES

How to specify DEBUG and RELEASE flags in Xcode with Swift or Objective-C

This tutorial shows you how to selectively run your debug or production code using flags.  Sometimes you may find it necessary to only run some code in Debug mode and other code in Release mode.

Swift

  1. Open your Project Build Settings and search for “Swift Compiler – Custom Flags” … “Other Swift Flags”.
  2. Add -DDEBUG to the Debug section
  3. Add -DRELEASE to the Release section DebugReleaseFlags
  4. In Swift you can use the following code:

    #if RELEASE
    // release only code
    #else
    // debug only code
    #endif
    

    or

    #if DEBUG
    // debug only code
    #else
    // release only code
    #endif
    

Objective-C

  1. In Objective-C, the DEBUG flag is already defined as a preprocessor macro.  However, you will need to add the RELEASE flag by going to your Project Build Settings and searching for Preprocessor Macros.
  2. Add RELEASE=1 to the Release section
  3. In Objective-C you can ue the following code:

    #ifdef RELEASE
    // release only code
    #else
    // debug only code
    #endif
    

    or

    #ifdef DEBUG
    // debug only code
    #else
    // release only code
    #endif
    

 

 

Get insights into your Apple Search Ads performance and optimize your bids and keywords for maximum revenue with Kitemetrics by Kitefaster.

 

Tested with the following versions:

  • Xcode 7.2
  • iOS 9.2.1
  • tvOS 9.1
  • Swift 2.1.1


Our Products

Kitemetrics
Keyword level attribution for Apple Search Ads. Optimize your bids and increase your revenue. Sign up for free at kitemetrics.com.

White Noise and Deep Sleep Sounds
Calming and relaxing sounds that will help you sleep like a baby tonight.
Download for free from the App Store.
Get it on Google Play.




Our Sponsors

Get Sleepy
Get Sleepy
The free podcast that puts you to sleep with meditative bedtime stories. Listen at getsleepy.com.