Set DEBUG to false - iphone

I want to test the below lines of code :
#ifdef DEBUG
#define VAR 10
#else
#define VAR 20
#endif
In project->build settings->preprocessor macros I had DEBUG=1 and NSLogging the value of VAR logged 10. Then I set DEBUG=0 to check if it loggs 20. But it logged 10 only.How to set DEBUG value so that else condition in code is satisfied?

Just make it easy:
#define DEBUG 1
#ifdef DEBUG
#define debug(...) NSLog(__VA_ARGS__)
#else
#define debug(...)
#endif
When you summit to appstore, comment #define DEBUG 1 :D
This is the way I used.
I dont know how to define something like you but it's great if it's possible!
Could you show me how to do that?

You should NOT be setting DEBUG=0 to get the right result.
Just don't define DEBUG at all to get release behavior.
Remember, #ifdef DEBUG code checks if DEBUG is defined or not.
Alternatively, #if DEBUG code would get you the right result.

As Aditya said, other library used in application may have defined DEBUG macro and hence even I remove it from preprocessor macro the condition #ifdef DEBUG is always satisfied. The solution is simple though. Just use different macro name such as IS_DEBUG instead of DEBUG. This solved my problem. It was a matter of just a macro name.

Related

Port COM is not appear STM32F4 tinyUSB

I'm trying to add tinyUSB library but I get this define CFG_TUSB_RHPORT1_MODE as not defined.With this line I have problem. If i comment this line, my usb is not appear in device manager. I did this tutorial. Could you check what i'm doing wrong (link to repo below)?
At the end I want to make CDC communication without misc.
Okey I solved issue. Silly I did't think to change number from 1 to 0... so it looks now:
if (!(rhport == 1 && (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED))) usb_otg->GCCFG |= USB_OTG_GCCFG_PWRDWN;
and in tusb_config.h I added:
#define CFG_TUSB_MCU OPT_MCU_STM32F4
#define CFG_TUSB_OS OPT_OS_NONE
#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
#define BOARD_DEVICE_RHPORT_NUM 0
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)
Now its working :D Discussion can be closed
Had similar issue with RHPORT1 in my case - STM32F407:
#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_NONE)

Is there any way to clear NSLog Output?

I have been googling from last couple of hours for finding that is there any way to clear NSLog output using code or not?
Like we have clrscr() in c. So if we are trying to print something which we want to focus most and there is lots of log printin there we can put that code there and get keep our desire log on top for easy searching. This can be done by putting breakpoint on my NSLog line and than click on clear console. but question is is there a way to achive this programatically?
I found few question on stack overflow but I din't satisfied with answer like this is saying that I can disable log for release mode etc.
Or I can use DLog, ALog or ULog as requirement but my question is different..
Any one can help me in this?
Thanks in advance :)
You can use a conditional breakpoint to simulate it. Define a function like this in your code:
int clear_console()
{
NSLog(#"\n\n\n\n\n\n\n\n");
}
Then, when you want to clear the console just add a breakpoint before the NSLog with this condition:
Condition: 1 > 0
Action: Debugger Command expr (int) clear_console()
Options: Automatically continue after evaluating Check it to skip the pause.
Tested with Xcode 4.3.2 and lldb.
Previous answer:
AFAIK, no, there isn't.
Just in case you're not doing it yet, you can create custom macros to format the output to highlight what you want.
Define macros like this:
#define CLEAR(...) NSLog(#"\n\n\n\n\n\n") /* enough \n to "clear" the console */
#define WTF(...) CLEAR();NSLog(#"!!!!!!!!!!!!!!");NSLog(__VA_ARGS__)
#define TRACE(__message__) NSLog(#">>>>>>>>>>>>>>> %# <<<<<<<<<<<<<<<<<<<", __message__)
Then:
WTF(#"This should't be here object: %#", theObject);
...
TRACE(#"Start Encoding");
...
It's not what you want but it pretty much solves the problem. You'll end up with your own set of macros with custom prefixes easily scannable in the console output.

How to use code inside #ifdef SHOUTCAST_METADATA

I am using code of "Matt Gallagher" for streaming player
and there are some code inside
#ifdef SHOUTCAST_METADATA
//Code
#endif
The system is not able to go inside these blocks.
Now currently the code inside is not working.....the code just needed to get the name of the stream playing.
Please help
Add this at the top of the file w/that #ifdef:
#define SHOUTCAST_METADATA 1
Of course, you'll need to deal with any dependencies incurred; that code was compiled out for a reason.

Suppressing NSLog statements for release? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Do I need to disable NSLog before release Application?
I wonder if someone could help me setup a number of NSLog statements so they print to console when executing in "Debug Mode" but don't print in "Release Mode". I understand I need to add something like DEBUG = 1 to the debug config in Xcode but I can't find where. Also how do I utilise this in my code?
NSLog(#"Print Always");
if(DEBUG) NSLog(#"Print only in debug");
Is there a simple way of doing this?
EDIT_001:
I tried following this but the keys now seem to be only listed under "All Settings", and are presenting as nice names. The one I should be using is GCC_PREPROCESSOR_DEFINITIONS, so I needed to find "Preprocessor Macros", select edit and add DEBUG=1
When you come to use this its simply a case of adding (see below) or some marco to remove the messy #ifdef / #endif tags.
NSLog(#"You always see me?");
#ifdef DEBUG
NSLog(#"Only in DEBUG");
#endif
This is a popular solution:
http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog
See comments about using either -DDEBUG=1 or DEBUG=1.
The best solution is not to use NSLog in the first place but instead rely on the debugger.
You can set breakpoints that execute debugger commands to print out anything and you can set the breakpoints to execute the debugger commands but not to stop execution. In practice this works just like NSLog.
By using the debugger to do the logging, you don't have to worry about removing the log statements.
Please have a look at the answers of How to print out the method name and line number and conditionally disable NSLog?. There are some nice macros in there that can be very useful.
I use this:
-(void)debugWinLog
{
NSUserDefaults * defaultsDebug = [NSUserDefaults standardUserDefaults];
theDebugWin = [defaultsDebug boolForKey:#"logger"];
}
Which is called in the awakeFromNib.
It checks the apps plist file for a 1 or 0 for the BOOL entry "logger"
The normal state if off, but when debugging you can then turn it on or off at will in terminal. with the normal defaults write.
The NSlog statments look like:
if ( theDebugWin) {NSLog (#"%#", windowState );}

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
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
Actually you can get the target's name to compare it, but this will not skip unnecessary code from other targets at compile time, to do this:
First go to menu Product -> Scheme -> Edit Scheme... (or CMD + <)
Then in the arguments section, add inside environment variables something like:
In your code you can get the target's name as:
NSString *targetName = [[NSProcessInfo processInfo] environment][#"TARGET_NAME"];
NSLog(#"target = %#", targetName); // Will print the target's name
You can compare that string now in runtime.
But following your example: if you want that all the Pro version code to be omitted at compile time. You should do what #jason-coco says. And go to preprocessor macros in build settings, and add $(TARGET_NAME) there:
The code inside the #define will be compiled and executed if my target is "MLBGoldPA"
#if defined MLBGoldPA
NSLog(#"Compiling MLBGoldPA");
#endif
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.