Tutorial :Error with objective-c macro


Im new to writing macros in Xcode and am having a problem writing my own NSLog replacement. I've been using a few examples but want to tweak them slightly, so they act more like Log4.

Im trying to write a 2nd macro (or ideally just a delegate of the first) which takes a log level variable as well as the string and arguments for formatting. But everytime I try and pass a varible (in this case l) I get a SIGART error NSArgumentException. The first macro works fine

#define MLog(s,...) \  [MLog logFile:__FILE__ lineNumber:__LINE__ \  format:(s),##__VA_ARGS__]    #define MLogWithLevel(l,s,...) \  [MLog logFile2:__FILE__ lineNumber:__LINE__ logLevel:l \  format:(s),##__VA_ARGS__]  

This is my method definition

+(void)logFile:(char*)sourceFile           lineNumber:(int)lineNumber          format:(NSString*)format, ...;    +(void)logFile2:(char*)sourceFile         lineNumber:(int)lineNumber          logLevel:(int)logLevel          format:(NSString*)format, ...;  

The exceptions:

+[MLog logFile2:lineNumber:logLevel::format:]: unrecognized selector sent to class 0x51600 2010-07-10 10:49:21.408 Celebspotter[34433:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[MLog logFile2:lineNumber:logLevel::format:]: unrecognized selector sent to class 0x51600'

My test log message:

MLogWithLevel(0: @"log at level %i", 0);  



Drop the colon, use a comma:

MLogWithLevel(0, @"log at level %i", 0);  // fix here:   ^   

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »