美文网首页iOS开发知识小集
Xcode控制台输出内容不全

Xcode控制台输出内容不全

作者: 申申申申申 | 来源:发表于2019-05-16 12:22 被阅读46次

小伙伴反应有时候控制台打印json内容不全
如下图

  1. 这是之前用的,如下
#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif

改成了,如下

#ifdef DEBUG
// #import <UIKit/UIKit.h>
#define NSLog(FORMAT, ...) printf("%s %s: %s: %d\t%s\n\n", [((id(*)(void))method_getImplementation(class_getClassMethod(NSObject.class, @selector(ff_getConsoleLogOfTime))))() UTF8String], [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"] UTF8String], [[[NSString stringWithUTF8String: __FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat: FORMAT, ## __VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif

ff_getConsoleLogOfTime是放在NSObject分类中

+ (NSString *)ff_getConsoleLogOfTime {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    return [dateFormatter stringFromDate:[NSDate date]];
}
  1. 但是报错,如下

因为没有找到对应的定义,导入头文件即可 #import <UIKit/UIKit.h>
  1. 修改完成后,重新编译发现许多警告

这是因为在使用这个宏的时候,当前文件没有找到这个方法

  1. 我们可以忽略这个警告
    方法1:这种方式需要在每个NSLog显式指定编译器忽略该警告,麻烦,弃之
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
NSLog(@"用户未录入指纹"); 
#pragma clang diagnostic pop

方法2:Undeclared Selector 改为 No

方法3:Other Warning Flags 添加 -Wno-undeclared-selector

三种方法都行,我选第二种,不要问为什么,因为懒,哈哈~

  1. version

不定期更新 不合适的地方 还请指点~ 感激不尽

相关文章

网友评论

    本文标题:Xcode控制台输出内容不全

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