目前,我们正在为自己定义一个扩展的日志机制来打印出类名和日志的源行号。
#define NCLog(s, ...) NSLog(@"<%@:%d> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
例如,当我调用 NCLog(@"Hello world"); 输出将是:
<ApplicationDelegate:10>Hello world
现在我还想注销方法名称,如:
<ApplicationDelegate:applicationDidFinishLaunching:10>Hello world
因此,当我们知道调用了哪个方法时,这将使我们的调试变得更容易。我知道我们也有 Xcode 调试器,但有时我也想通过注销来进行调试。
最佳答案
print(__FUNCTION__) // Swift
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
Swift 3 及以上版本
print(#function)
https://stackoverflow.com/questions/2770307/