scan-build finds things Build and Analyze does not

Ever since I started using the latest Xcode, I’ve loved having scan-build built in as Build and Analyze. I did feel like it was less thorough, but I didn’t have time to prove it — now I have.

There is one kind of bug that scan-build was very good at finding — forgetting to set retained properties to nil in dealloc isn’t found by default in Build and Analyze. It’s not even part of the default scan-build any more (not sure why — it was great).

Anyway, I recommend using scan-build directly instead of Build and Analyze. Here’s how:

  1. Download scan-build
  2. Just unpack it into any directory and add that directory to your PATH
  3. Open a Terminal and cd to your project’s root directory
  4. Run scan-build and view results

Here is a scan-build line that works for iOS 4.0:

scan-build -analyzer-check-objc-missing-dealloc -analyzer-check-llvm-conventions –experimental-checks -k -V -o scan-reports xcodebuild -configuration Debug -sdk iphonesimulator4.0 clean build

I’ve turned on all checks, and now it catches if you forget to set properties to nil in dealloc.

Run Build and Analyze often in Xcode, but every once and a while, run a full scan-build with the latest version as it finds problems that the Xcode version will not.

UPDATE: Instructions on getting this working in Xcode from the Build and Analyze menu

Get iPhone programming tips in your inbox with my Beginner iPhone Programming Tips newsletter.