美文网首页
关于 Xcode NSLog 输出不全的问题

关于 Xcode NSLog 输出不全的问题

作者: 胡胡LoL | 来源:发表于2017-10-18 14:54 被阅读206次

Xcode8.0中用NSLog打印长的 json 显示不全,我们可以采用printf来打印

1.一些比较实用的宏:

(1)FUNCTION ://获取当前方法名;

(2)func ://获取当前方法名;

(3)PRETTY_FUNCTION ://获取当前方法名;

(4)LINE ://获取当前所在行;

(5)FILE ://获取该文件的绝对路径;

(6)DATE ://获取当前日期;

(7)TIME ://获取当前时分秒;

(8)TIMESTAMP ://获取当前时间戳;

2.使用 printf 写成一个宏

#define NSLog(format, ...) printf("TIME:%s FILE:%s(%d行) FUNCTION:%s \n %s\n\n",__TIME__, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])

3.由于 Log 打印耗用资源,所以再对其进行优化

1.debug 模式

#ifdef DEBUG
#define HHLog(format, ...) printf("\n%s HHLog %s(line%d) %s\n%s\n\n", __TIME__, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
#else
#define HHLog(format, ...)
#endif

2.Optimization Leve优化方式

#ifndef __OPTIMIZE__  //优化方式 Optimization Leve
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...){}
#endif

相关文章

网友评论

      本文标题:关于 Xcode NSLog 输出不全的问题

      本文链接:https://www.haomeiwen.com/subject/unbsuxtx.html