美文网首页iOS Learning
Xcode 打印信息常用的Debug表达式

Xcode 打印信息常用的Debug表达式

作者: codingchou | 来源:发表于2018-05-10 16:09 被阅读0次

定义打印格式

- (void)testLog {
    NSLog(@"\n Function: %s\n Pretty function: %s\n Line: %d\n File: %s\n Object: %@",__func__, __PRETTY_FUNCTION__, __LINE__, __FILE__, self);

}

func, PRETTY_FUNCTION, LINE, FILE等都是系统预留的定义词,简单易用。

手动忽略clang编译器警告, 表达式可以在xcode 的快捷区域调出,不需要手写,如下图所示:

截图1

常见用法:

1、方法弃用警告
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    //code这里插入相关的代码
    #pragma clang diagnostic pop
2.不兼容指针类型
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Wincompatible-pointer-types"
     //code这里插入相关的代码
     #pragma clang diagnostic pop
3.retain cycle
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Warc-retain-cycles"
     //code这里插入相关的代码
     #pragma clang diagnostic pop
4.未使用变量
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "--Wunused-variable"
     //code这里插入相关的代码
     #pragma clang diagnostic pop
5.selector中使用了不存在的方法名(在使用反射机制通过类名创建类对象的时候会需要的)
     #pragma clang diagnostic push
     #pragma clang diagnostic ignored "-Wundeclared-selector"
     //code这里插入相关的代码
     #pragma clang diagnostic pop

clang更多用法

相关文章

网友评论

    本文标题:Xcode 打印信息常用的Debug表达式

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