Question

I am just starting out with xcode and learning Objective-C & Cocoa, would it be helpful to swap the compiler in Xcode 3.2 to Clang for the enhanced error checking and static analyser. I am just curious if the extras given would be helpful or would my learning be better served sticking to the default settings?

many thanks

gary

Was it helpful?

Solution

There are a few options for using CLANG:

  1. Run build and analyze, to see clang results.

  2. In project settings for a configuration, you can check the "run static analyzer" box and CLANG will be run each time you compile.

  3. You can also change the compiler from GCC 4.x to CLANG/LLVM. That displays more errors and CLANG warnings (one example is that NSLog(@"A value is %@:%@", value) will warn you you are not passing in enough parameters).

I would recommend option 2 - if you run the static analyzer with each build, it doesn't take much more time and you'll find out if you are doing something odd right away, rather than fixing a bunch of errors later. The clear messages it give you actually provide a lot of educational value, so it makes even more sense to turn it on if you are just learning!

Option 3 is good to run from time to time because of the greater error checking. However, currently XCode has no CLANG/LLVM compiler for the iPhone device, and so you can only use that setting when compiling for the simulator. The best approach then is to create a copy of the debug configuration (in the project settings configurations tab) named "Debug CLANG", and set that configuration to use the CLANG/LLVM compiler and run the static analyser. Note that after you create a new configuration you have to back out of settings, select it as the active configuration (via the top right dropdown) and then go back in to project settings to edit the values.

Then in day to day use you simply use the "Debug" setting to compile using the static analyzer, and switch to "Debug CLANG" perhaps once a week to see if any deeper problems exist.

OTHER TIPS

You can use the static analyser without using the actual Clang compiler. Generally you wouldn't use the analyser as your default build option as it slows build times a fair bit.

However, the Clang compiler is a good option even without considering static analysis. It has much better error reporting as you point out, but the main advantage is that it's very fast, in fact in my testing it's almost twice as fast as GCC.

If you "Build and Analyze" or turn on the "Run Static Analyzer" preference in XCode, you get Clang's static analysis.

If you're not doing C++ development, there doesn't appear to be much downside to switching from gcc to Clang. You just don't need to do so to get the benefits of Clang's static analysis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top