objective c - Enable and Disable NSLog in DEBUG mode -
i want enable nslog when in debug , disable otherwise. simple thing is:
#ifdef debug nslog(@"my log"); #endif
but #ifdef
, #endif
borring... :( try other thing: (.pch place put it)
#ifdef debug # define nslog(text) nslog(text); #else # define nslog(text) #endif
this work fine (isn't recursive). problem nslog have infinite arguments.
void nslog(nsstring *format, ...)
how solve work in preprocessor mode?
-- edit --
this code make nslog better:
#ifdef debug #define nslog(format, ...) fprintf(stderr,"%s\n", [[nsstring stringwithformat:format, ##__va_args__] utf8string]); #else #define nslog(...) #endif
this should trick:
#ifdef debug # define nslog(...) nslog(__va_args__) #else # define nslog(...) (void)0 #endif
Comments
Post a Comment