Xcode 7.3 Analyzer Improvements

The latest xcode beta is available for downloading. There are many improvements, and the usual problems with stuff that stops working… Ah the love of Apple for it’s developers :). But I want to tell you about a feature that caught my attention: New analyzer settings!

New analyzer settings

From the release notes:

The static analyzer warns when nil is returned from a method or function with a nonnull return type or is passed to a parameter marked nonnull.

The static analyzer checks for common misuses of Objective-C generics.

The static analyzer checks for missing localizability. This check is off by default and can be enabled by selecting ‘Yes’ for ‘Missing localizability’ in the ‘Static Analyzer - Generic Issues’ build settings.

There are 3 new settings related to these new features: CLANG_ANALYZER_NONNULL, CLANG_ANALYZER_OBJC_GENERICS and CLANG_ANALYZER_LOCALIZABILITY.

CLANG_ANALYZER_NONNULL and CLANG_ANALYZER_OBJC_GENERICS

Objective-C continues to get some love! Adding into the changes for nullability and generics, now the analyzer will start to warn you about usage not in line with your annotations. That’s very good news, considering that the compiler checks were a bit lacking. Additional kudos because both settings are enabled by default.

CLANG_ANALYZER_LOCALIZABILITY

This is an intriguing one. Let’s investigate further; Let’s say you have some code where you set a string to a label:

1
label.text = @"not-localized";

You’ll now get a nice analyzer warning: “User-facing text should use localized string macro”

warning1

But you won’t get a warning when the key is not localized. Like:

1
label.text = NSLocalizedString(@"not-localized", nil);

Hey, we can’t have everything, but here’s my request for improvement submitted.

Anyway, go ahead and enable these new settings! And use the analyzer!