It bothered me too, so I wrote a function to replace NSLog()
and printf()
:
void IFPrint (NSString *format, ...) {
va_list args;
va_start(args, format);
fputs([[[[NSString alloc] initWithFormat:format arguments:args] autorelease] UTF8String], stdout);
va_end(args);
}
Then, you can just use it instead of NSLog()
(e.g. IFPrint(@"Current date: %@", [NSDate date])
), but it won't print out any timestamps or a newline, and you don't have to mess around with C strings and arrays, and whatnot. It's pretty handy, I'd say.
If you want, check out my full code (I've also written a replacement for fprintf, scanf, and fscanf) here.
(There's also an SO topic about it here).