Search code examples
iosobjective-cxcodeclang

nullability-completeness warning since Xcode 9.3


The "nullability-completeness" warning is not working in Xcode 9.3 (and 9.4.1) for me. It works though in Xcode 9.1 and 9.2.

I created a new iOS project in Xcode 9.2 (or 9.1) with the "Single View App" template, then add this method to my ViewController.h:

- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;

I'm getting 2 warnings on each of the arguments as expected like so:

In file included from /Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.m:9:
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;
                              ^
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: note: insert '_Nullable' if the pointer may be null
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;
                              ^
                               _Nullable
/Users/daniel/Projects/tests/TestNullability92/TestNullability92/ViewController.h:13:31: note: insert '_Nonnull' if the pointer should never be null
- (nonnull UIView *)f:(UIView *)f g:(UIView *)g;

But if I open and rebuild that project in Xcode 9.3 (or 9.4.1) - I don't get those warnings.

I tried going to the build settings and enabling this flag explicitly (although it should be enabled by default), but still got nothing:

enter image description here


Solution

  • There was a bug with Xcode from 9.3 to 10.1 that no-nullability-completeness flag did not work as expected.

    This was fixed in Xcode 10.2, it produces the right warnings again: if the flag is enabled (it should be enabled by default), the pointer object arguments and return values in header files are required to have nullability annotations (or be inside NS_ASSUME_NONNULL_BEGIN blocks). If the annotations are missing, the compiler warning is produced as expected.