1

I am working on a project with multiple targets, I have a preprocessor macro in build settings:

PRODUCT_NAME=\@\"$PRODUCT_NAME\"

now in AppName-Prefix.pch I have defined the $PRODUCT_NAME as:

#define ACTIVE_PRODUCT PRODUCT_NAME

how can I check if ACTIVE_PRODUCT is equal to a string?

I want to do something like this e.g.

if ACTIVE_PRODUCT == @"Product 1"
#define MY_VAR @"Test 1
#endif

if ACTIVE_PRODUCT == @"Product 2"
#define MY_VAR @"Test 2

So I can use MY_VAR in my code depending on the $PRODUCT_NAME

Please assist! regards, Bill.

zoul
  • 102,279
  • 44
  • 260
  • 354
Nimrod7
  • 1,425
  • 2
  • 17
  • 30

2 Answers2

1

I think there’s a previous question for that, and the answer seems to be that it’s not possible (see the comp.lang.c FAQ). What I try to do is avoid the preprocessor as soon as possible, moving all processing to Objective-C. So instead of #defining your variables, you may set a regular Objective-C variable and continue processing in Objective-C:

static NSString *const ProductName = /* create string from PRODUCT_NAME */;

And later:

NSString *const MyVar = [ProductName isEqualToString:…] ? @"Foo" : @"Bar";

Of course this assumes that you only need MyVar in source code, not in resources like plists.

Community
  • 1
  • 1
zoul
  • 102,279
  • 44
  • 260
  • 354
1

Ok since comparing strings seems not possible I used the following walkaround:

in each target I defined PRODUCT1=\@\"$PRODUCT_NAME\" .... PRODUCT2=\@\"$PRODUCT_NAME\" etc.

then in app-name-prefix.pch I did the following:

#if defined (PRODUCT1)
#define MY_VAR @"Test 1"
....
#endif

#if defined (PRODUCT2)
#define MY_VAR @"Test 2"
...
#endif

This solved the problem in my case. Any other ways will be appreciated also.

Nimrod7
  • 1,425
  • 2
  • 17
  • 30