1

A question for general improvements of the code. I have an enum with configurations for the app:

    enum Configuration
    {
        static let useTestServer = true
        *etc*
    }

How can I check that useTestServer == false every time I archive the app for the app store? Cause there is always possibility to forget turning test server off while publishing.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Eduard
  • 516
  • 1
  • 4
  • 17

1 Answers1

1

You could use preprocessor macros and check for the existence of the predefined DEBUG symbol:

#if DEBUG
    // TODO: debug build setup
    static let useTestServer = true
#else
    // TODO: release build setup
    static let useTestServer = false
#endif

DEBUG is typically set to 1 at the target level (Targets > (your target) > Build Settings > Preprocessor Macros > Debug).
This question contains relevant information about preprocessor macros: #ifdef replacement in the Swift language
Hope this helps.

Community
  • 1
  • 1
Olivier
  • 858
  • 8
  • 17
  • So, I can just use this construction in the AppDelegate to print("Don't use the test server while archiving, mate!") and it will be executed when the build is getting ready? – Eduard Feb 14 '17 at 14:42
  • #if / #else / #endif are compile-time macros so a print() won't have any effect until the code is actually run. What you might want to do is write `static let useTestServer = true` in the #if DEBUG block and `static let useTestServer = false` in the #else block. I edited my answer to clarify. – Olivier Feb 14 '17 at 14:51