最安全的方法就是,找到警告的位置直接修改。
這是方法是最好的的,也是最安全的。但是有的時候,確實會出現一下不可避免的警告,對于這種警告就可以做一些適當的忽略操作。做忽略之前需要先知道警告的類型。
查看警告
警告原因
中括號內的內容就是警告的原因。找到警告的原因之后就要做忽略設置了
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警告