You have confusing methods and functions - Objective-C has both. NSLog is a standard function, so you call it NSLog(...) . You have defined a method:
-(void)DNSLog:(NSString *)formatString, ...
but tried to call it a function. To call your method, you need to do:
[self DNSLog:@"Hello %d", x];
Since your code is compiling, you must have a global or instance debug variable. If it is global, you can define DNSLog as a function (this will not work if debug is an instance variable, since only those methods can access them directly). The function will start:
void DNSLog(NSString *formatString, ...)
The body of the function will be the same as for the method.
NSLog also has the NS_FORMAT_FUNCTION attribute to tell the compiler that it takes a format string as an argument, seeing this, the compiler checks the string and format arguments to make sure they match. To do this for your method or function, write:
-(void)DNSLog:(NSString *)formatString, ... NS_FORMAT_FUNCTION(1,2);
or
void DNSLog(NSString *formatString, ...) NS_FORMAT_FUNCTION(1,2);
in an interface or header file.
NTN.
source share