0

I have Swift project in which I have installed my SDK by cocoapods. In Swift project I have configured LOCAL, STAGING, and PRODUCTION schemes. When I switch schemes, Xcode recognizes which one to compile, but this is woking only on the Swift project but not ObjC. Is there a way to change only the Swift project configuration, which will work either on swift and SDK which is installed by cocoapods?

This is my code which must be compiled

#if LOCAL
    NSLog(@"SDK: local");
#elif STAGING
    NSLog(@"SDK: staging");
#else
    NSLog(@"SDK: production");
#endif

I have tested and it seems working when I include this in my sdk podspec

s.pod_target_xcconfig = {'GCC_PREPROCESSOR_DEFINITIONS' => 'LOCAL=1'}

but in this way no matter which scheme I use, the SDK only compiles the LOCAL.

I've seen that some cocoapod libs are installed like this

pod 'LIB', :path => '../../', :configuration => ['Debug']

but in my case this doesn't work.

Kevin
  • 53,822
  • 15
  • 101
  • 132
Gog Avagyan
  • 135
  • 1
  • 7

1 Answers1

0

Swift can read #define's from a C or Objective-C header file, but not from the configuration. As a solution, put for example CONFIG_LOCAL into your configuration, and a line #define LOCAL CONFIG_LOCAL into a header file that is read by Swift. Any #define with a plain integer constant as its value gets turned into a global variable with an Int32 value in Swift, so then you would write

if LOCAL != 0 {
    NSLog("SDK: local")
} else if STAGING != 0 {
    NSLog("SDK: staging")
} else {
    NSLog("SDK: production")
}

LOCAL and STAGING must both be defined with integer values in an Objective-C header filer.

gnasher729
  • 51,477
  • 5
  • 75
  • 98