我想创建一个自定义NSLog()
方法,DNSLog()
,只有在调试变量为true时才执行NSLog
。自定义NSLog方法(变量)
-(void)DNSLog:(NSString *)formatString, ...
{
if(debug){
va_list args;
va_start(args, formatString);
NSLog([[NSString alloc] initWithFormat:formatString arguments:args]);
va_end(args);
}
}
但是当我尝试使用
DNSLog(@"Hello %d",x);
调用它,我收到一个编译错误:
Undefined symbols for architecture i386:
"_DZNSLog", referenced from:
-[RestaurantInfoViewController viewDidLoad] in RestaurantInfoViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已经使用这个作为参考:http://www.cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
我在哪里出错了?
我想你应该在学习C之前尝试进入先进的东西。看起来你甚至不能区分C函数的语法和Objective-C方法...... – 2013-06-06 05:19:10
此外,你的代码容易受格式字符串攻击/错误的影响。你应该使用'NSLogv(formatString,args);'来代替。 – 2013-06-06 05:20:54