How to print out the method name and line number a

2018-12-31 23:12发布

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently.

In particular, I have two questions:

  • is there a way to easily NSLog the current method's name / line number?
  • is there a way to "disable" all NSLogs easily before compiling for release code?

13条回答
泪湿衣
2楼-- · 2018-12-31 23:55

Disabling all NSLogs, for somebody allergic to MACROS, here is something that you can compile too:

void SJLog(NSString *format,...)
{
    if(LOG)
    {   
        va_list args;
        va_start(args,format);
        NSLogv(format, args);
        va_end(args);
    }
}

And, use it almost like NSLog:

SJLog(@"bye bye NSLogs !");

From this blog: http://whackylabs.com/rants/?p=134

查看更多
登录 后发表回答