1

I've decided it would be easiest if I replace my NSLog calls with another function....

+(void)logThis:(NSString*)line{ 

#ifdef DEBUG 
NSLog(line); 
#endif  

}

However, I'm going to have to replace 215 NSLog calls, it would be a lot quicker if my function accepted multiple paramaters like NSLog, then all I would have to do is find and replace NSLog with my function name / class, then the extra bracket to a square bracket.

Can anyone tell me now I can add such parameter acceptance into my function ?

OR a quicker / better solution, which wouldn't mean adding more lines of code instead of NSLog ?

Jules
  • 7,568
  • 14
  • 102
  • 186
  • Have a look at my edited answer to your previous question; it links to how to use a macro to have a drop-in replacement for NSLog(). – paulbailey Feb 01 '11 at 16:09
  • 1
    http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ - read down to DLog. – Eimantas Feb 01 '11 at 16:30
  • you should always use a string literal as your first argument to NSLog, even if it's as simple as: `NSLog(@"%@",line);`. if you use the variadic approach, then you'll also want to know about `NSLogv`. – justin Feb 02 '11 at 04:51

2 Answers2

1

What you need is a variadic function. These functions take a flexible number of arguments, like NSLog, [NSArray arrayWithObjects:...], etc.

See this tutorial:

http://www.numbergrinder.com/node/35

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
  • +1 very useful tutorial (and probably better than macro hacks, because it leaves the option of turning logging on/off at runtime). – David Gelhar Feb 01 '11 at 16:19
0

How about making a macro "NSLOG_IF_DEBUGGING" that expands to "NSLog" or "(void)", depending on whether or not it's a debugging build? Then you would just globally replace all your NSLog calls with NSLOG_IF_DEBUGGING.

David Gelhar
  • 27,873
  • 3
  • 67
  • 84