Objective C - Defining macro to call a method? Objective C - Defining macro to call a method? objective-c objective-c

Objective C - Defining macro to call a method?


Assuming that logString:withLogLevel: takes a single string parameter in addition to the log level, this should be possible:

#define DLog(x) [Logger logString:(x) withLogLevel:LogLevelDebug]

Note the parentheses around the macro parameter, it is useful when macros are called with composite expressions.

Assuming that the logger takes NSString objects, not C string, you should use the macro like this:

DLog(@"Text");

However, in this case it is not clear why would one prefer a macro to a simple function call:

void DLog(NSString *str) {    [Logger logString:str withLogLevel:LogLevelDebug];}