的NSLog与iPhone的Objective-C中的方法名 [英] NSLog the method name with objective-C in iPhone
本文介绍了的NSLog与iPhone的Objective-C中的方法名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我们正在定义自己的扩展日志机制,打印出来的类名和日志的源代码行数。
的#define NCLog(S,...)的NSLog(@<%@:%d取代;%@,[[的NSString stringWithUTF8String:__ FILE__] lastPathComponent] \\
__LINE__,[的NSString stringWithFormat:(S),## __ VA_ARGS__])
例如,当我打电话NCLog(@的Hello world);
输出将是:
< ApplicationDelegate:10 -10世界,你好
现在我也想注销方法的名称,如:
< ApplicationDelegate:在applicationDidFinishLaunching:10 -10世界,你好
所以,这将使我们的调试变得更加容易,当我们可以知道哪种方法获取调用。我知道,我们也有X code调试,但有时,我也想通过注销做调试。
解决方案
打印(__ FUNCTION__)//斯威夫特
的NSLog(@%@,NSStringFromSelector(_cmd)); // Objective-C的
Currently, we are defining ourselves an extended log mechanism to print out the class name and the source line number of the log.
#define NCLog(s, ...) NSLog(@"<%@:%d> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
For example, when I call NCLog(@"Hello world"); The output will be:
<ApplicationDelegate:10>Hello world
Now I also want to log out the method name like:
<ApplicationDelegate:applicationDidFinishLaunching:10>Hello world
So, this would make our debugging become easier when we can know which method is getting called. I know that we also have XCode debugger but sometimes, I also want to do debugging by logging out.
解决方案
print(__FUNCTION__) // Swift
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
这篇关于的NSLog与iPhone的Objective-C中的方法名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文