I made a custom logging class that logs certain things to a file. I’m trying to make a macro so that I can use my custom class just like NSLog(), but it doesn’t seem to be working right.
Here’s how I’m defining the macro:
#define ECLog(fmt, ...) [ECLogger logText:fmt, ## __VA_ARGS__]
logText: is declared like this:
+ (void)logText:(NSString *)theString;
If I only pass one argument, it works fine. Like this:
ECLog(@"test");
But if I pass another argument, like this:
ECLog(@"test %@",someString);
I get an error that it was only expecting one argument.
Any ideas?
No, the warning is about the method call. The error seems to be about the macro because you’re viewing the code before the preprocessor has worked on it, but the compiler’s pointing to the same line, post-processing.
You’ve declared this method as taking one argument, but you’re passing it more than that.
gets rewritten by the preprocessor to:
That’s the literal text that is now passed to the compiler, just as if you’d typed it that way yourself. The method is declared as taking a single
NSString, but you’re passing it two things. You need to change the declaration of the method: