Matthew Morey

I'm an engineer, developer, author, hacker, creator, tinkerer, traveler, snowboarder, surfer, and husband.

I create iOS apps professionally and independently.

Automatic Static Analysis with Xcode

17 April 2014

Keith Harrison: Running Custom Clang Analyzer Builds

The Clang Static Analyzer has long been integrated with Xcode and provides powerful source code analysis to detect bugs in C, C++ and Objective-C code. The analyzer is fully open source and part of the larger Clang project. This means that you do not need to wait for Apple to release a new version of Xcode to get the latest updates to the analyzer.

Great tip by Keith, I just wish I could remember to run the analyzer (Product > Analyze or ⇧⌘B). Turns out you can have Xcode run the analyzer every time you build. Problem solved.

To enable this Xcode feature search for "static analyzer" in your project build settings and set "Analyze During Build" to "Yes". You probably also want to set "Mode of Analysis for Build" to "Deep".

Run the static analyzer automatically with each build in Xcode

You might not want to do this if you have a massive Xcode project or you're on a slow machine as this will increase build times. For most iOS projects being built on modern hardware the minor slowdown is probably not noticeable.