title: How to download and set a UIImage not on the main thread
body: <p>I'm adding an image from a web service. How would I code this so that it's not on the main thread? I want the view to load first and then the image to load so that the user doesn't experience any slowness when the detail view controller loads.</p>
  
  <p>What I'm unsure of is how to add this into the dispatching code.</p>
  
  <p>here's my code so far:</p>
  
  <pre><code>   NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:mainImageUrl]];
  UIImage *image = [[UIImage alloc] initWithData:imageData];
  
  UIView *v = [[UIView alloc] initWithFrame:CGRectMake(10, 150, 300, 180)];
  UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 300, 180)];
  [iv setImage:image];
  
  [_scrollView addSubview:v];
  [v addSubview:iv];
  </code></pre>
  
  <p>and this is what I'm thinking I can use for the threading:</p>
  
  <pre><code>dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  // Add code here to do background processing
  //
  //
  dispatch_async( dispatch_get_main_queue(), ^{
      // Add code here to update the UI/send notifications based on the
      // results of the background processing
  });
  </code></pre>
  
  <p>});</p>
  
  <p>thanks for the help</p>