I have two targets for my project: one is the App, and the other is UT.I'd like to return different results for one method depending on the target.
I followed this link but failed.
I tried both:
TARGET_NAME
. I set OTHER_CFLAGS
to contain -DTARGET_NAME=${TARGET_NAME}
in the project setting. And then in the code:
NSString *returnStr = nil;
#if TARGET_NAME == PhotoAPI
returnStr = [NSString stringWithFormat:@"%@\'%@\');",EventFunStr,dataStr];
#elif TARGET_NAME == LogicTest
returnStr = [NSString stringWithFormat:@"%@", dataStr];
#endif
return returnStr;
However it seems TARGET_NAME == PhotoAPI
is always true.
2. I also use Preprocessor Macros
, and I set APP
for the App targtet and UT
for UT. And In the code:
NSString *returnStr = nil;
#ifdef APP
returnStr = [NSString stringWithFormat:@"%@\'%@\');",EventFunStr,dataStr];
#elsedef UT
returnStr = [NSString stringWithFormat:@"%@", dataStr];
#else
returnStr = nil;
#endif
return returnStr;
And It always return nil
.
I use LLVM GCC 4.2
.
Can anyone help me?
The problem may be i the way you define the flags heres a good doc on using it to call NSLog only in DEBUG
http://iphoneincubator.com/blog/debugging/how-to-create-conditional-log-statements-in-xcode
it said in comments If you’re going to use GCC_PREPROCESSOR_DEFINITIONS instead of OTHER_CFLAGS, make sure to use the form “DEBUG=1″ instead of “-DDEBUG=1″