title: iPhone SDK: Checking the ID number for each object in a UITableView and change the badge number accordingly
body: <p>I'm tryin to use some code to create a badge number for the iPhone App Icon.</p>
  
  <p>I can successfully do this, however the code I am using (below) is pretty bad and could easily be done better, however I do not have the logic knowledge to be able to do this.</p>
  
  <p>This is what it's doing...</p>
  
  <ol>
  <li>Get's the 'ID' of a user from the first message in a UITableView. It then checks this against the stored ID (from the first object when it was last loaded) and makes the badge number 1.</li>
  <li>Then checks the second ID in a message to see if that is the same as the stored. If not it will make the badge number 2.</li>
  <li>etc etc..</li>
  </ol>
  
  <p>What I want it to do is automatically check the IDs and add '1' to the badge number until the first post with the correct ID is found however, I'm not too sure on the coding.</p>
  
  <p>Any help would be great!</p>
  
  <p>Thanks</p>
  
  <p>(The code is below:)</p>
  
  <pre><code>        NSDictionary* tweetValues = [[NSDictionary alloc] init];
      tweetValues = [tweets objectAtIndex:1];
      NSString *newStatusID = [[tweetValues objectForKey:@"id"] stringValue];
      NSString *oldStatusID = [[NSUserDefaults standardUserDefaults] stringForKey:@"latestID"];
      [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
      if([newStatusID isEqualToString:oldStatusID]){
          [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
      } else {
          tweetValues = [tweets objectAtIndex:2];
          newStatusID = [[tweetValues objectForKey:@"id"] stringValue];
  
          if ([newStatusID isEqualToString:oldStatusID]){
              [UIApplication sharedApplication].applicationIconBadgeNumber = 1;
          }else{
  
              tweetValues = [tweets objectAtIndex:3];
              newStatusID = [[tweetValues objectForKey:@"id"] stringValue];
  
              if ([newStatusID isEqualToString:oldStatusID]){
                  [UIApplication sharedApplication].applicationIconBadgeNumber = 2;
              }else{
                  [UIApplication sharedApplication].applicationIconBadgeNumber = 3;
              }
          }
  
      }
  </code></pre>