0

I'm trying to define the type of the build by using those 3 variables, but for some reason, it always uses the first one. Any ideas?

// Pay attention: only ONE of these modes MUST be chosen.
//
//
#define DEVELOPMENT 0
#define PRODUCTION 1
#define STORE 0

This is how I use it:

#ifdef DEVELOPMENT
    NSLog(@"Development version built.");
#elif STORE
    NSLog(@"Store version built.");
#else
    NSLog(@"Distribution version built.");
#endif

It's always entering the first ifdef..

ytpm
  • 4,962
  • 6
  • 56
  • 113
  • Because it is "defined", isn't it? Try commenting DEVELOPMENT and STORE lines and try again. – EDUsta Sep 27 '15 at 11:20
  • comment DEVELOPMENT & STORE in the define part? – ytpm Sep 27 '15 at 11:21
  • Yep, but I would recommend changing your method since you want to compare the values of the macros. Your current problem is that you're checking if they are "defined", you're not comparing the values. – EDUsta Sep 27 '15 at 11:23
  • (check this: http://stackoverflow.com/questions/2303963/c-macro-if-check-for-equality) – EDUsta Sep 27 '15 at 11:29

1 Answers1

3

I got what you want to do. You have to do it a liiiitle bit different. You have to do it like this:

#if DEVELOPMENT
    NSLog(@"Development version built.");
#elif STORE
    NSLog(@"Store version built.");
#else
    NSLog(@"Distribution version built.");
#endif

Bacause as @EDUsta has stated, #ifdef checks if this macro is defined at all. If yes - then it will be evaluated to true. In your case you have to check for value, so you have to use #if.

Soberman
  • 2,556
  • 1
  • 19
  • 22