title: iPhone OS: making a switch statement that uses string literals as comparators instead of integers
body: <p>So I'd like to do this:</p>
  
  <pre><code>switch (keyPath) {
      case @"refreshCount":
          //do stuff
      case @"timesLaunched":
         //do other stuff
  }
  </code></pre>
  
  <p>but apparently you can only use integers as the switch quantity. Is the only way to do this parse the string into an integer identifier and then run the switch statement?</p>
  
  <p>like this:</p>
  
  <pre><code>nsinteger num = nil;
  
  if (keyPath isEqual:@"refreshCount") {
  
  num = 0
  
  }
  
  if (keyPath isEqual:@"timesLaunched") {
  
  num = 1
  
  }
  </code></pre>
  
  <p>I'm trying to optimize this code to be as quick as possible because its going to get called quite often.</p>
  
  <p>thanks,</p>
  
  <p>Nick</p>
  
  <p>NOTE: Yes I'm using KVO so I am recieving a string in the "callback."</p>
  
  <p>NOTE #2: So what made me first consider the switch statement is my original code implementation was like this:</p>
  
  <pre><code>if ([keyPath isEqual:@"refreshCount"] &amp;&amp; ([[change valueForKey:@"new"] intValue] == 10)) { //  
  NSLog(@"achievemnt hit inside");
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"Achievement Unlocked!" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
      [alert show];
  </code></pre>
  
  <p>I want to do a bunch of these with different XX values all in the same method:</p>
  
  <pre><code>if ([keyPath isEqual:@"refreshCount"] &amp;&amp; ([[change valueForKey:@"new"] intValue] == 10)) {
  
  //unlock small achievement
  
  }
   if ([keyPath isEqual:@"refreshCount"] &amp;&amp; ([[change valueForKey:@"new"] intValue] == 50))   {
  
  //unlock bigger achievement
  
  }   
  
  //etc
  </code></pre>
  
  <p>This just seemed very inefficient to me but maybe I'm wrong.</p>