How To Create Conditional Log Statements in Xcode
A simple method to debug your iPhone application code is to use NSLog() statements at strategic points. I often find myself printing out the response from server calls using NSLog. Even after the iPhone client development is done, these log statements can be useful to debug server issues. But you obviously don’t want to fill the console log in your released code.
To skip lines of code you don’t want to include in the release build you can use a preprocessor instruction:
#ifdef DEBUG
NSLog(@"Server Response: %@", response);
#endif
Unfortunately Xcode does not automagically define DEBUG when you do a debug build. So you have to add a definition to your project target.
pre:Project ->getInfo->Builder
1. Be sure you select Debug in the Configuration drop down.
2. Select Settings Defined at This Level in the second drop down to reduce the number of fields shown.
3. Now click the tool button in the bottom left corner and select Add User-Defined Setting from the menu.
4. Enter the following name value pair:
OTHER_CFLAGS -DDEBUG=1
note:the "OTHER_CFLAGS" equals to "Preprocessor Macros",if the xcode warn that " There’s already another key named", then search and edit "Preprocessor Macros", make sure the value is "debug=1" instand of "-DDEBUG=1"
浙公网安备 33010602011771号