4

I want some code to only be executed in a release build, but the code does not get executed when the scheme is configured to use the release configuration.

What am I missing?

I have the following in my app delegate's didFinishLaunchingWithOptions method:

#if RELEASE
    Countly.sharedInstance().startOnCloudWithAppKey(appKey)
    Crittercism.enableWithAppID(appID)
    NSLog("crash logging enabled")
#endif

The target build settings look like this: screenshot of the Swift Compiler - Custom Flags section in Xcode

And the scheme is configured to use the Release configuration when I run the app: Screenshot of release scheme configuration in Xcode

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Ben Thomas
  • 1,416
  • 2
  • 17
  • 25

3 Answers3

4

You will need to set the preprocessor flags explicitly in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line.

Please check-

In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project

Community
  • 1
  • 1
Shripada
  • 6,296
  • 1
  • 30
  • 30
2

It looks like the Swift compiler ignores -D flags that assign a specific value. If you use -DDEBUG and -DRELEASE, it seems to work.

user157005
  • 91
  • 2
0

now you need to set

Active Compilation Conditions

under Swift Compiler - Custom Flags

e.g.

Active Compilation Conditions DEV

you can check

#if DEV
  print("DEV mode")
#else 
  print("PROD")
#endif 
Devesh.452
  • 893
  • 9
  • 10