Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check the TARGET_NAME of my iPhone app on XCode?

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

like image 298
onigiri Avatar asked Jun 22 '09 13:06

onigiri


People also ask

Where is Product_name defined Xcode?

The PRODUCT_NAME is defined in the target's Build Settings in the Packaging section. It has the same name by default as your project.

How do I change the author name in Xcode?

For changing author name in Xcode 6, just go to User & Groups in system preferences, right click current user (make sure permission is unlocked), select Advanced Options , change the "Full name" section.

How do I rename targets in Xcode?

Rename the Target to Rename the App Select the project from the project navigator to open the project editor and see a list of the app's targets. To rename a target, select it, press the Return key, and enter the new name. If all you want to do is rename the app, you're finished.


1 Answers

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
like image 101
Jason Coco Avatar answered Nov 02 '22 13:11

Jason Coco