消除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#>"
影响范围包括该行下面所有内容

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容