ObjC advanced static code analyzer

There is a built in code analyzer in Xcode but unfortunately it’s not that we really need. It doesn’t check complexity, method sizes etc.

This was one of the missing features till now because fortunately there is a good one out already: OCLint (http://oclint.org/)

Unfortunately there is still no correct Xcode project file read support in it, but there is a dirty solution by recursively read all the .m files in a folder. On the developer’s site there is a basic script for it. Since it was a bit old I updated the script and now works well with the latest Xcode.

Just put the following script into a .sh file and run in the root folder of the project (check the paths before run)

#! /bin/bash

LANGUAGE=objective-c
ARCH=armv7
SYSROOT=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
CLANG_INCLUDE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/3.1/include
PCH_PATH=target-Prefix.pch
FRAMEWORKS='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/'

INCLUDES='-I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include'
for folder in `find . -type d`
do
  INCLUDES="$INCLUDES -I $folder"
done

FILES=''
for file in `find . -name "*.m"`
do
  FILES="$FILES $file"
done

oclint -x $LANGUAGE -arch $ARCH -isysroot=$SYSROOT -F $FRAMEWORKS -I $CLANG_INCLUDE $INCLUDES $FILES