title: Objective-C Switch Statement
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1231198/declaring-variables-inside-a-switch-statement">Declaring variables inside a switch statement</a>  </p>
  </blockquote>
  
  
  
  <p>I'm having difficulty getting XCode to let me write a particular switch statement in Objective-C. I'm famiiar with the syntax and could rewrite it as if/else blocks but I'm curious.</p>
  
  <pre><code>switch (textField.tag) {
          case kComment:
              ingredient.comment = textField.text;
              break;
          case kQuantity:
              NSLog(@""); // removing this line causes a compiler error           
              NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
              fmt.generatesDecimalNumbers = true;
              NSNumber *quantity = [fmt numberFromString:textField.text];
              [fmt release]; 
              ingredient.quantity = quantity;
              break;
      }
  </code></pre>
  
  <p>I can't see the syntax error, it's as though I need to trick the compiler into allowing this.</p>