xcode警告处理

处理格式

#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警告处理)