title: Unrecognized Selector Error when writing dictionary values to file in iOS
body: <p>I'm reading an array of ALAsset objects (delcared as <code>NSMutableArray *assets;</code> in the header file). I'm trying to follow <a href="http://iphonedevelopertips.com/data-file-management/read-and-write-array-dictionary-and-other-collections-to-files.html" rel="nofollow">this example</a> in order to print the contents of an ALAssets dictionary to file to be retrieved later. Note that I can properly write the dictionary key to file (commented out), but not the value. </p>
  
  <p>Here is my code which runs at the end of the viewDidLoad() method:</p>
  
  <pre><code>// Create path to Documents
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  
  if ([paths count] &gt; 0) {
      NSString *dictPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"dict.out"];
      NSDictionary *aDict = [[assets objectAtIndex:0] valueForProperty:ALAssetPropertyURLs];
  
      for (id key in aDict) {
          NSLog(@"key: %@, value: %@", key, [aDict valueForKey:key]);  
          //[key writeToFile:dictPath atomically:YES];        &lt;- THIS LINE WORKS
          [[aDict valueForKey:key] writeToFile:dictPath atomically:YES];            
      }
  }
  else
      NSLog(@"nope");    // The program doesn't get here.
  </code></pre>
  
  <p>The log looks like this:</p>
  
  <blockquote>
    <p>2011-11-17 23:44:41.340 PhotoApp[542:12803] key: public.jpeg,
    value: assets-library://asset/asset.JPG?id=1000000001&amp;ext=JPG</p>
    
    <p>2011-11-17 23:44:41.361 PhotoApp[542:12803] -[NSURL
    writeToFile:atomically:]: unrecognized selector sent to instance
    0x6455650 </p>
    
    <p>2011-11-17 23:44:41.370 PhotoApp[542:12803] <em>*</em>
    Terminating app due to uncaught exception
    'NSInvalidArgumentException', reason: '-[NSURL
    writeToFile:atomically:]: unrecognized selector sent to instance
    0x6455650'</p>
  </blockquote>
  
  <hr>
  
  <p><strong>Edit</strong>: Not sure whether it matters, but the project is targeted for iPad, and is running on the simulator.</p>