title: How do I verify the contents returned from a queue match the UITableView cell they were intended for?
body: <p>I'm new to iOS development and this is my first question on stackoverflow even though I come here a lot.  Thanks for such a great resource!</p>
  
  <p>I'm taking the Stanford CS193P course and having trouble with "assignment 5 extra credit 1".<br>
  I have a UITableView that displays title, subtitle, and a thumbnail.  I queue up the thumbnail fetch but need to verify the table cell hasn't been recycled when the thumbnail image comes back.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Photo";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      }
  
      NSDictionary *imageDescription = [self.photoList objectAtIndex:indexPath.row];
      NSString *expectedPhotoID = [imageDescription objectForKey:FLICKR_PHOTO_ID];
  
      // Configure the cell...
  
      cell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
          UIImage *imageThumb = [self imageForCell:imageDescription];
          [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; // simulate 2 sec latency
  
          dispatch_async(dispatch_get_main_queue(), ^{
              NSString *photoID = [imageDescription objectForKey:FLICKR_PHOTO_ID];
              if ([expectedPhotoID isEqualToString:photoID]) {
                  cell.imageView.image = imageThumb;
              } else {
                  NSLog(@"cellForRowAtIndexPath: Got image for recycled cell");
              }
          });
      });
  
    return cell;
  }
  </code></pre>
  
  <p>In this code, <code>photoID</code> always matches <code>expectedPhotoID</code>.  I'm assuming it's because the <code>imageDescription</code> pointer is used for both queues at the time they are created.  I've tried using <code>[self.photoList objectAtIndex:indexPath.row]</code> directly (in place of <code>imageDescription</code>) but that didn't work either.  It appears that too is resolved at the time the queues are created.</p>
  
  <p>I'm missing some fundamental understanding here and appreciate your help.</p>