消除Xcode警告(OC警告)

1.CocoaPods警告消除 - inhibit_warnings => true

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'iOS进阶' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for iOS进阶
  pod 'RBScrollTextView', :inhibit_warnings => true
end

需要重新 pod install

2.Xcode常见OC警告消除

#pragma clang diagnostic push
#pragma clang diagnostic ignored "<#警告名称-Reveal in Log#>"
<#要消除警告的代码#>
#pragma clang diagnostic pop

警告名称通过右击警告,Reveal in Log查看
中括号中的"-Wunused-variable"即为该警告名称


Reveal in Log in Xcode

警告名称

3.拓展

当你需要在一段代码消除多种警告时,只需要添加多个警告类型

#pragma clang diagnostic ignored "<#警告名称-Reveal in Log#>"

实际情况如下


#import "RBPerson.h"
#import "RBNil.h"
@implementation RBPerson


- (void)test {
    RBEmpty *e = [RBEmpty emptyWithName:@""];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wunused-variable"
    RBEmpty *e1 = [RBEmpty new];
    e.name = @"";
    RBNil *n = [[RBNil alloc] init];
#pragma clang diagnostic pop
}

@end

只写一行
#pragma clang diagnostic ignored "<#警告名称-Reveal in Log#>"
影响范围包括该行下面所有内容

你可能感兴趣的:(消除Xcode警告(OC警告))