title: Can I load a UIImage from a URL?
body: <p>I have a URL for an image (got it from UIImagePickerController) but I no longer have the image in memory (the URL was saved from a previous run of the app).  Can I reload the UIImage from the URL again?  </p>
  
  <p>I see that UIImage has a imageWithContentsOfFile: but I have a URL.  Can I use NSData's dataWithContentsOfURL: to read the URL?</p>
  
  <h2>EDIT1</h2>
  
  <hr>
  
  <p>based on @Daniel's answer I tried the following code but it doesn't work...</p>
  
  <pre><code>NSLog(@"%s %@", __PRETTY_FUNCTION__, photoURL);     
  if (photoURL) {
      NSURL* aURL = [NSURL URLWithString:photoURL];
      NSData* data = [[NSData alloc] initWithContentsOfURL:aURL];
      self.photoImage = [UIImage imageWithData:data];
      [data release];
  }
  </code></pre>
  
  <p>When I ran it the console shows:</p>
  
  <pre><code>-[PhotoBox willMoveToWindow:] file://localhost/Users/gary/Library/Application%20Support/iPhone%20Simulator/3.2/Media/DCIM/100APPLE/IMG_0004.JPG
  *** -[NSURL length]: unrecognized selector sent to instance 0x536fbe0
  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL length]: unrecognized selector sent to instance 0x536fbe0'
  </code></pre>
  
  <p>Looking at the call stack, I'm calling URLWithString, which calls URLWithString:relativeToURL:, then initWithString:relativeToURL:, then _CFStringIsLegalURLString, then CFStringGetLength, then <strong>forwarding_prep_0</strong>, then <strong>forwarding</strong>, then -[NSObject doesNotRecognizeSelector].</p>
  
  <p>Any ideas why my NSString (photoURL's address is 0x536fbe0) doesn't respond to length?  Why does it say it doesn't respond to -[NSURL length]?  Doesn't it know that param is an NSString, not a NSURL?</p>
  
  <h2>EDIT2</h2>
  
  <hr>
  
  <p>OK, the only problem with the code is the string to URL conversion.  If I hardcode the string, everything else works fine.  So something is wrong with my NSString and if I can't figure it out, I guess that should go in as a different question.  With this line inserted (I pasted the path from the console log above), it works fine:</p>
  
  <pre><code>photoURL = @"file://localhost/Users/gary/Library/Application%20Support/iPhone%20Simulator/3.2/Media/DCIM/100APPLE/IMG_0004.JPG";
  </code></pre>