Xcode Compile Flag to Suppress Nullability Warning

2020-06-08 05:34发布

问题:

For a limited time I want to suppress these kind of warnings the compiler is showing me in Xcode 7.3.1:

<File>: Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

I have added this compiler flag to all classes under My Target/Build Phases/Compile Sources: -Wnullability-completeness

But it's not working - the warnings are still shown. How can I get rid of the warnings?

回答1:

To disable those warnings, you want: -Wno-nullability-completeness. Note the no-; the flag you're using enables those warnings.



回答2:

Note that in Xcode 11 it is now -Wno-nonnull

It should be set in "Other Warning Flags" in the "Apple Clang - Custom Compiler Flags" section of your target.

You could also avoid these warnings and setting the above altogether by removing these flags Xcode automatically adds to new header files in Objective-C:

NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END


回答3:

In Xcode 11.3, these started appearing out of nowhere in my pure Swift project on the Github ci. That was because I am importing the AWS Objective-C SDK.

Confoundingly, this would only occur on the first build, probably creating the module map for the framework. Hence it was only a problem on ci because of the clean builds.

Fixed it by adding this to the Swift compiler options (search for OTHER_SWIFT_FLAGS in your build settings):

-Xcc -Wno-nullability-completeness


回答4:

Settings for Xcode 11.5 when using project with mixed sources, ObjC and Swift:

WARNING_CFLAGS = $(inherited) -Wno-nullability-completeness
OTHER_SWIFT_FLAGS = $(inherited) -Xcc -Wno-nullability-completeness