Stanislav Pankevich Stanislav Pankevich - 3 years ago 181
Swift Question

Swift: how to maximize warnings in Xcode? What is the equivalent for -Wall in swiftc?

I have a number of Swift-only framework targets within a big iOS app project. I would like to explore the strictness of Swift compiler options to understand if they could give any additional benefits.

There are many warnings in Xcode but most of them seem to be Clang-related. What is the equivalent of

-Wall
or
-Weverything
that we could do for Swift compiler?

One example is a warning to prevent shadowing of the local variables:
Apple LLVM 9.0 - Warnings - All languages / Hidden local variables
: it is
GCC_WARN_SHADOW = YES
under the hood so it does not affect the
swiftc
compiler.

Answer Source

No. C accumulated layer-upon-layer of warnings and then barnacles like "warnings that aren't part of 'all warnings'" over many years and many compilers, coupled with a language that allows a lot of things you generally should never do.

Swift is young and has broken backward compatibility several times in its short life. It hasn't been around long enough to need bizarre backward-compatibilty options yet. Many of the things C adds as warnings, Swift just makes illegal or requires you make explicit.

That said, there absolutely are other layers of warnings that exist already. The first set are found via the static analyzer (Cmd-Shift-B in Xcode), and the second exist in tools like swiftlint which fills the same role as linters in C. The line between a linter and a compiler warning is vague and shifting, and you may see some things move from the linter to the compiler over time. But I still doubt you'll ever see a warning system as convoluted as GCC's (which Clang inherited).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download