views:

523

answers:

2

Hi, I'm trying to have 2 version of my iPhone application within the same XCode project. The codebase it's almost the same and where I need to have different behaviours I've decided to use preprocessor's conditionals and the ${TARGET_NAME} tag.

I've set the OTHER_CFLAGS to contain "-DTARGET_NAME=${TARGET_NAME}".

Then in my code I tried to do

#if TARGET_NAME == myApp
  NSLog(@"pro");
#elif TARGET_NAME == myAppLite
  NSLog(@"lite");
#endif

Unfortunately I always get "lite" printed out since TARGET_NAME == myApp it's always true: since TARGET_NAME is defined. I cannot for the life of me figure out how to evaluate this string comparison. Any idea?

thanks in advance

+2  A: 

You can't compare strings like that in an #if block. Instead, add the defines to each specific target. For instance, on the full version's target, open the Info panel and go to the build tab and add something like FULL_VERSION to the GCC_PREPROCESSOR_DEFINITIONS build setting. Then, for the lite target, enter something like LITE_VERSION. In your code, you can do:

#ifdef FULL_VERSION
NSLog(@"Full");
#else
NSLog(@"Lite");
#endif
Jason Coco
Thanks, I think I'll do in this way. At the beginning I was going for this solution anyway, but I got stuck with the #if block comparison since I've found those on some blogs (like "here":http://www.pacificspirit.com/blog/2009/01/27/building_for_multiple_iphone_targets_in_xcode ) but it seems it's impossible... thanks again
A: 

to get your conditional evaluation working, you have to do something like:

#define myApp    1
#define myAppLite   2

beforehand, like in your _Prefix.pch file.

lufasz