xcode 警告处理

最安全的方法就是,找到警告的位置直接修改。

这是方法是最好的的,也是最安全的。但是有的时候,确实会出现一下不可避免的警告,对于这种警告就可以做一些适当的忽略操作。做忽略之前需要先知道警告的类型。

查看警告
警告原因

中括号内的内容就是警告的原因。找到警告的原因之后就要做忽略设置了

1、对于特定位置的警告

这种方式适用于针对性比较强,并且不适合做全局忽略的警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "xxxxxxx"
code ...
#pragma clang diagnostic pop

举个例子

- (void)launchExecution {
    @autoreleasepool {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        // Start executing the requested task
        [targetForExecution performSelector:methodForExecution withObject:objectForExecution];
#pragma clang diagnostic pop
        // Task completed, update view in main thread (note: view operations should
        // be done only in the main thread)
        [self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO];
    }
}

2、全局忽略

适用于于不影响编译与逻辑的警告
在对应的targets 下 的Build Settings 下 设置 other warning flags
其中的参数为 将警告开头的-W改为 -Wno-。比如 -Wdocumentation 改为 -Wno-documentation

全局忽略

3、pod库中警告的处理

有时候引入的pod会带有一些未处理的警告,这种类型的警告只需在podfile文件中 添加 inhibit_all_warnings!来忽略所有的警告。

忽略pod警告

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容