Compile .h depending on the target that is running

1

I have two .h in my project with the same auto-generated name. Does anyone know how to compile one or the other depending on the target that is executed?

It is imperative not to change the name of .h

    
asked by jescabias 01.03.2016 в 14:43
source

1 answer

0

Good afternoon.

To do that kind of thing in Obj-C, precompiled sentences are often used. I'll explain a bit how they work.

We have two targets. ( Target1 and Target2 ) In the two targets we have to declare a preprocessor macro . For example AR_IMPORTS .

In Target1 we will give you the value 0 and in Target2 we will give you the value 1.

The macros are used by the compiler to know what to do in each moment.

For example you could put something like this in the code:

#import <Foundation/Foundation.h>

@class IETemplate;

@interface AKREngine : NSObject

-(instancetype)initWithRules:(NSArray<NSDictionary *> *)rules;

#if AR_IMPORTS

-(void)run;

#endif

-(void)close;

@end

In this case you can check that when the variable AR_IMPORTS is true, that is, greater than 0 the compiler will compile the run method, if it is false, it will not.

    
answered by 09.05.2017 в 16:43