将*某些*警告视为Swift中的错误? [英] Treat *some* warnings as errors in Swift?

查看:88
本文介绍了将*某些*警告视为Swift中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下我在Swift中标记以下不推荐使用的方法

@available(*, deprecated=1.0)
func myFunc() { 
    // ...
}

然后我将警告视为Swift中的错误,方法是设置 OTHER_SWIFT_FLAGS =-warnings-as-errors

如何使这些弃用通知显示为警告,同时仍将其余警告视为错误?

How do I make it show these deprecation notices as warnings, while still treating the rest of the warnings as errors?

似乎 GCC有一个很好的解决方案解决此问题:

-Werror // treat all warnings as errors
-Wno-error=<warning> // don't treat <warning> as error (e.g. -Wno-error=switch)
-Werror=<warning> // treat <warning> as error

因此,如果这是Objective-C,我可以简单地使用- Werror -Wno-error = deprecated-declarations 并得到我想要的。

So if this was Objective-C, I could simply use -Werror -Wno-error=deprecated-declarations and get exactly what I want.

Swift的等效项是什么?

What is the equivalent for Swift?

我尝试在<$ c中添加 -Wno-error = deprecated-declarations $ c> OTHER_SWIFT_FLAGS ,但似乎它并不适用于Swift,因此它不起作用。

I tried adding -Wno-error=deprecated-declarations to the OTHER_SWIFT_FLAGS, but it seems like it's not meant for Swift, so it doesn't work.

推荐答案

这是不可能的。从Swift 4开始,Swift编译器没有开关来启用/禁用特定警告或将特定警告提升为错误。

This isn't possible. As of Swift 4, the Swift compiler doesn't have switches to either enable/disable particular warnings or promote particular warnings to errors.

Swift核心开发人员表示不愿意在swift-evolution邮件列表中的多个场合中添加一连串的编译器标志。这样做的理由是,他们希望保留一个Swift的方言,以便每个开发人员都使用相同的语言功能,等等。

The Swift core developers expressed their reluctance to add a litany of compiler flags on several occasions on the swift-evolution mailing list. The rationale is that they want to keep a single "dialect" of Swift so that every developer works with the same language features etc.

警告标记当然值得商,,但这是目前的官方立场。将来很有可能会放宽这些规则,但我不会打赌。

Whether this should extend to something like particular warning flags is of course debatable, but that's the current official stance. It's definitely possible that these rules will be somewhat loosened in the future, but I wouldn't bet on it.

这篇关于将*某些*警告视为Swift中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆