美文网首页
xcode警告处理

xcode警告处理

作者: 扣肉快快跑 | 来源:发表于2019-08-02 13:59 被阅读0次

处理格式

#pragma clang diagnostic push
#pragma clang diagnostic ignored "警告类型"
    //有黄色警告的代码
#pragma clang diagnostic pop

警告类型

 //声明变量未使用  "-Wunused-variable"
    //方法定义未实现  "-Wincomplete-implementation"
    //未声明的选择器  "-Wundeclared-selector"
    //参数格式不匹配  "-Wformat"
    //废弃掉的方法     "-Wdeprecated-implementations"
    //废弃掉的API     "-Wdeprecated-declarations"
    //不会执行的代码  "-Wunreachable-code"
    //在arc 环境下performSelector产生的 leaks 的警告 "-Warc-performSelector-leaks"
    //类别方法覆盖的警告 "-Wobjc-protocol-method-implementation"

例子

- 声明变量未使用
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
    NSString *string = @"";
#pragma clang diagnostic pop
- 方法定义未实现
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
@implementation ClearWarningVC
#pragma clang diagnostic pop
- 未声明的选择器
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)]];
#pragma clang diagnostic pop
- 废弃掉的API
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"" otherButtonTitles:@"", @"", nil];
    [alertView show];
#pragma clang diagnostic pop
- 不会执行的代码
if (NO) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
        NSLog(@"狗子,你好呀!");
#pragma clang diagnostic pop
    }
- 废弃掉的方法
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(nullable NSError *)error NS_DEPRECATED(10_7, 10_13, 5_0, 8_0) {
    //信号强度改变时调用的方法(iOS5~8可用)
    NSLog(@"外围信号(旧)--->%@", peripheral.RSSI);
}
#pragma clang diagnostic pop

相关文章

  • xcode 警告处理

    最安全的方法就是,找到警告的位置直接修改。 这是方法是最好的的,也是最安全的。但是有的时候,确实会出现一下不可避免...

  • Xcode 警告处理⚠️

    2. Silencing “Documentation issue” warnings in Xcode? E....

  • xcode警告处理

    处理格式 警告类型 很有趣的连接 例子 - 声明变量未使用 - 方法定义未实现 - 未声明的选择器 - 废弃掉的A...

  • Xcode报错和警告处理

    1、linker command failed with exit code 1(use -v to see in...

  • [iOS]Xcode中警告处理

    强迫症的福利, 有的时候, 我们特别讨厌Xcode中的代码警告, 以下就是遇到各种警告的时候的处理方法:(后续会一...

  • ios琐碎笔记

    抛出异常&异常处理 NSInvocation执行多参数方法 强制消除Xcode警告 UI控件对齐方式属性 UINa...

  • 怎么去掉Xcode工程中的某种类型的警告

    怎么去掉Xcode工程中的某种类型的警告 怎么去掉Xcode工程中的某种类型的警告

  • Xcode警告

    Block implicitly retains 'self'; explicitly mention 'self...

  • Xcode 警告

    http://www.cocoachina.com/ios/20141218/10678.html https:/...

  • Xcode8_Warning_Couldn’t communic

    警告 升级Xcode8后提交代码,执行commit操作,出现以下警告 升级Xcode8后shift + commo...

网友评论

      本文标题:xcode警告处理

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