ios - How to enable parts of code with external files .plist or .xcconfig -


i have project i'm using fastlane toolchain build.

i have multiple deployment targets (hockey app, test flight, app store) - , each deployment i'm interested in disabling , enabling features.

for example - when i'm doing alpha build enterprise cert hockeyapp want disable flurry analytics.

when i'm doing beta build want change app-id and/or change flurry key

i have working in fastlane variety of sed commands search , replace files etc.

that being said, i'm sure there better way.

i know in obj-c can #ifdef against build environment flags enable / disable parts of code. best way go in swift.

do use sort of custom .plist file or .xcconfig setting tell app do/use or there different way?

the things i'm interested in are

  • disabling portions of code ( ignore function in specific config)
  • changing values used in code aka api_key or that

you can still use similar #ifdef preprocessor in swift, , can combine .xcconfig can used specify various variables. scripts can generate values go .xcconfig vars.

the basic setup be:

  1. create .xcconfig file , associate desired build configurations (in project settings -> info).
  2. add variables .xcconfig. example, if want activate alpha build can this: is_alpha_build=-d alpha. notice -d necessary here. scripts can leave variables empty if want flag turned off.
  3. in build settings target, under "swift complier - custom flags" - > "other swift flags" add flag based on .xcconfig file variables: ${is_alpha_build}. if .xcconfig setup correctly should see content of variable once you're done editing variable.
  4. use flags in code:

    #if alpha     print("alpha") #else     print("not alpha") #endif 

i hope helps, or @ least give idea best approach suitable you.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -