Objective c 在Xcode中重新定义NSLog

Objective c 在Xcode中重新定义NSLog,objective-c,nslog,Objective C,Nslog,我有一个关于Xcode和Objective-C的问题 我想在Xcode中执行以下简单操作: 如果我键入以下内容: NSLog(@"something else"); 我希望Xcode写入(或编译后执行): 另一种方法是Xcode 4在“自动完成”菜单中建议这样做,当我键入NSLog…时,您可能更希望生成一个宏并将其放入预编译头(.pch)文件中 (摘自)为什么不使用其他一些非常优秀的替代选项,如我在这里写的SOSMAX或NSLogger这是一套完整的日志定义指令(包括ULog,一种基于UIAl

我有一个关于Xcode和Objective-C的问题

我想在Xcode中执行以下简单操作:

如果我键入以下内容:

NSLog(@"something else");
我希望Xcode写入(或编译后执行):


另一种方法是Xcode 4在“自动完成”菜单中建议这样做,当我键入NSLog…

时,您可能更希望生成一个宏并将其放入预编译头(.pch)文件中


(摘自)

为什么不使用其他一些非常优秀的替代选项,如我在这里写的SOSMAX或NSLogger

这是一套完整的日志定义指令(包括ULog,一种基于UIAlertView的日志功能)

正如作者所写,只需将它们放在预编译头(.pch)文件中


(来源:)

顺便说一句,对于调试,我建议使用
@“%s:something other”,\uuu函数\uuu
代替,它将沿着
-[MyClass myMethod]:something other
的行输出一些内容。
@“%s[行%d]”
fmt
之间的分号将此错误消除。它应该只是一个空间。谢谢,修复了万一有人复制/粘贴它。
NSLog(@"[%@] something else", NSStringFromClass([self class]));
#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif
// DLog will output like NSLog only when the DEBUG variable is set

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

// ALog will always output like NSLog

#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

// ULog will show the UIAlertView only when the DEBUG variable is set 

#ifdef DEBUG
#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define ULog(...)
#endif