Xcode:抑制所有外部库的所有警告

Xcode: suppressing all warnings for all external libraries

要禁用编译器警告,我转到 Project -> Target -> Build Settings并添加标志

-w

针对特定文件。此标志禁用文件的 所有 警告。

但有时这个标志不起作用

例如,当我 运行 测试时,我收到外部库 Nimble 的警告(我用标志 -w 标记的所有这些文件):

.../Pods/Nimble/Sources/Nimble/Matchers/MatcherProtocols.swift:15:11: 'Matcher' is deprecated: Use to Predicate instead .../Pods/Nimble/Sources/Nimble/Matchers/Predicate.swift:170:22: 'Matcher' is deprecated: Use to Predicate instead .../Pods/Nimble/Sources/Nimble/Matchers/AllPass.swift:22:27: 'Matcher' is deprecated: Use to Predicate instead .../Pods/Nimble/Sources/Nimble/Matchers/AllPass.swift:76:21: Variable 'generator' was never mutated; consider changing to 'let' constant .../Pods/Nimble/Sources/Nimble/Matchers/AsyncMatcherWrapper.swift:41:14: 'Matcher' is deprecated: Use to Predicate instead

我做错了什么以及如何消除对我没有影响的外部库的警告?

根据你问题中的日志,我在你的项目中看到 cocoapods。只需将 inhibit_all_warnings! 标志添加到您的 podfile,此标志将隐藏使用 cocoapods.

安装的第三方库的编译警告

有关使用 inhibit_all_warnings! 标志的更多详细说明,请参阅 alloy's answer

快速修复

我看到你在使用 cocoapods。 Cocoapods 会在您每次 运行 pod install 时重写您的配置。因此,您需要在 podfile 中添加此行以忽略 所有警告 特定 pod 的警告:

# example to ignore all warnings from all pods
inhibit_all_warnings!

# example to ignore warnings from a specific pod
pod 'Alamofire', :inhibit_warnings => true

注意:有时也能看到您的警告和您的 pod 的警告,这样您就可以防止将来出现问题。