Xcode 4.6 Tip: Set Compiler Warning For Empty Loops

With the release of Xcode 4.6 you can set a compile time warning when you inadvertently write a loop which has an empty body. For example, the semi-colon at the end of the ‘if’ statement below is a problem:

- (void)doSomething:(int)x
{
  // Semi-colon at end of 'if'
  if (x == 0);
  {
    NSLog(@"Made it here...");
  }
 
...
 
}

Which is really equivalent to the following, as the semi-colon ends the if statement:

if (x == 0);
 
NSLog(@"Made it here...");

Continue reading