iPhone: Suppress NSLog in production? -


i got bunch of nslog statements in code. there anyway can suppress them executing in production, execute when i'm developing? want not comment them out, , them put them in when developing, it's hassle.

debug macro defined (xcode default) when doing debug/development build of project. cause code between #ifdef debug , #endif lines not included when doing release build compiled , included debug/dev/test build.

example:

#ifdef debug     nslog(@"hello world!"); #endif 

this use in project-prefix.pch file (called debuglog(@"abc %@", somestr);):

#ifdef debug     extern void dbgquietlog(nsstring *format, ...);     #define debuglog(fmt, ...) dbgquietlog((@"[line: %d] %s: " fmt), __line__, __function__, ##__va_args__); #else     #define debuglog(fmt, ...) #endif  #ifdef debug     void dbgquietlog(nsstring *format, ...) {         if (format == nil) {             printf("nil\n");             return;         }         va_list arglist;         va_start(arglist, format);         nsstring *s = [[nsstring alloc] initwithformat:format arguments:arglist];         printf("%s\n", [[s stringbyreplacingoccurrencesofstring:@"%%" withstring:@"%%%%"] utf8string]);         [s release];         va_end(arglist);     } #endif 

this prints console lines (only when debugging) line number, class name, , method name so:

[line: 36] -[iphoneappdelegate application:didfinishlaunchingwithoptions:]: hello world! 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -