Enable Compiler Warnings To Your Advantage

Ole Begemann has written an excellent piece on how to get the most out of compiler warnings. This is information is worth digesting as it relates to understanding Xcode compiler warnings.

From Ole:

Compiler warnings are one of the most helpful tools for developers. The compiler can not only warn you about obvious mistakes (such as a method you forgot to implement); it also identifies many code patterns that, though syntactically correct, are potentially dangerous (like signed/unsigned conversion) or just plain wrong (such as mismatched format specifiers in a format string).

I agree with Ole, use the tools the compiler provides. When the compiler issues a warning, it warrants a closer look at your code.

And here’s a great tip from Ole’s post, you can disable warnings for section of code, where the rest of the file is not affected:

// Code tip from Ole Begemann
// http://oleb.net/blog/2013/04/compiler-warnings-for-objective-c-developers/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-compare"
int i = 100;
unsigned int u = 200;
if (i < u) {  // no warning
#pragma clang diagnostic pop