title: Crash when loading Core Data images into UITableViewCell on background thread
body: <p>I have a series of profile pictures stored in Core Data as <code>Binary Data</code> (with the <strong>Allows External Storage</strong> option enabled, so don't jump on me for storing images in Core Data :)</p>
  
  <p>Each image is being displayed in a <code>UITableViewCell</code>. At the moment there is a slight delay when the user taps to display the table view, presumably because it is loading them from Core Data which has a sufficient enough performance implication to lock-up the UI when loading them on the main thread.</p>
  
  <p>I would like to put the image loading onto a separate background thread, so that the table view appears immediately and the images show when they have been loaded from Core Data.</p>
  
  <p>I have tried the solution <a href="https://stackoverflow.com/questions/7502073/loading-images-from-a-background-thread-using-blocks/7502281#7502281">in this post</a> with the following code in the <code>-cellForRowAtIndexPath:</code> method:</p>
  
  <pre><code>    // Create the cell
      MyCell *cell = [tableView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
  
          // Get a reference to the object for this cell (an array obtained from Core Data previously in the code)
          MyObject *theObject = [self.objectArray objectAtIndex:indexPath.item];
  
          // Load the photo from Core Data relationship (ProfilePhoto entity)
          UIImage *profilePhoto = [UIImage imageWithData:theObject.profilePhoto.photo];
  
          // Set the name
          cell.nameLabel.text = theObject.name;
  
          dispatch_sync(dispatch_get_main_queue(), ^(void) {
  
              // Set the photo
              cell.photoImageView.image = profilePhoto;
  
          });
  
      });
  
      // Return the cell
      return cell;
  </code></pre>
  
  <p>However, the app crashes with the following error (repeated for each row in the table view):</p>
  
  <pre><code>CoreData: error: exception during fetchRowForObjectID: statement is still active with userInfo of (null)
  </code></pre>
  
  <p>Any help on understanding and resolving this issue would be appreciated.</p>