title: Asynchronously loading images on the iPhone
body: <p>I have a grid of images that are loaded from the web, but there's a bit of lag/stutter while scrolling. I'm using an asynchronous <code>ASIHTTPRequest</code> to make the requests, so the download itself is happening in a separate thread, but because UIKit isn't thread-safe, once I receive the <code>NSData</code> response, I have to call <code>UIImage initWithData</code> on the main thread.</p>
  
  <p>Profiling shows that, by far, the bottleneck consists of the internal PNG parsing functions invoked by <code>UIImage initWithData</code>. I'm interested in doing this in a background thread, so the main UI remains responsive and there's less lag.</p>
  
  <p>But I'm not sure exactly how to do this. It sounds like the right direction is to use <code>CGImageRef</code>, since Core Graphics is thread-safe, but I only see <code>CGImageCreateWithPNGDataProvider</code> and <code>CGImageCreateWithJPEGGDataProvider</code>, whereas <code>UIImage initWithData</code> supports a large list of image types.</p>
  
  <p>I want something that has the same functionality as <code>UIImage initWithData</code> but doesn't have the thread-safety issues.</p>