Add BETA = 1 macro to Xcode for specific schemas?

I want to add a new #define macro to my application, but only for certain schemes, such as a beta scheme. What is the best way to do this? I know that when you run the application in test mode (i.e. in the simulator), it adds the macro DEBUG = 1, but I cannot figure out how to add more.

+4
source share
3 answers

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 own macros for each type of assembly.

Beta.xcconfig:

 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=1 

Distribution.xcconfig.

 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=0 

You can easily add files using the new file dialog box:

Create a xcconfig file

Then you need to map each file to the build style. Get the top-level project, project parameters (directly above the target objects) and click "Information":

Map xcconfigs to build styles

In your code, you can use the macro as usual:

 #if BETA // do something only in beta #endif 

If, instead of assigning a value, you simply define a macro, you should use #ifdef .

If you use multiple macros, you may need to verify that everything is working properly in your build logs:

build logs with macros highlighted

+6
source
Schemes

perform assembly configurations only

macros can only be set for assembly configurations

create a new assembly configuration and a new scheme for its use

this is a bit uncomfortable: /

+3
source

An alternative (I used) would be in the build settings for your project or goal.

1) Go to Project → Target → Build Settings
2) Find the "preprocessor macros"

Now you should see all the schemas defined for this project and add all the preprocessor macros that you like. Just remember to leave $ (inherited). Also, you probably want to save all the other specific macros, since in my case I had the definition of COCOAPODS = 1.

0
source

Source: https://habr.com/ru/post/1448080/


All Articles