I want to add a new #define
macro to my app, but only for certain schemes, like a beta scheme. What is the best way to do this? I know that when you are running the app in test (i.e. in simulator) it adds a DEBUG=1 macro, but I can't figure out how to add more ones.
The best way is to use Xcode configuration files.
Add a couple of files named Beta.xcconfig
and Distribution.xccconfig
(or something like that) and add your macros for each kind of build.
Beta.xcconfig:
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=1
Distribution.xcconfig.
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=0
You can add the files easily with the new file dialog:
Then, you need to map each file to a build style. Got to top level project, project settings (right above targets) and click "Info" section:
In your code you can use the macro as always:
#if BETA
// do something only in beta
#endif
If instead of assigning a value you just define the macro you should use #ifdef
.
If you use several macros you may need to check that everything is working as expected looking in your build logs:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With