title: Cocoa: Getting image file metadata
body: <p>I am building an app that allows users to select a file and/or folder either locally or across the network and list the contents of that selection in a NSTableView after some filtering (no hidden files, only accepting .tif, .eps). The user can then select a file name from the list and then have the files metadata shown to them. At least that is what I want to happen. Right now I am getting null returned for the metadata. Here's my code: </p>
  
  <pre><code>- (void)tableViewSelectionDidChange:(NSNotification *)notif {
  
  NSDictionary* metadata = [[NSDictionary alloc] init];
  
  //get selected item
  NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]];
  
  //set path to file selected
  NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData];
  
  //declare a file manager
  NSFileManager* fileManager = [[NSFileManager alloc] init];
  
  //check to see if the file exists
  if ([fileManager fileExistsAtPath:filePath] == YES) {
  
      //escape all the garbage in the string
      NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8);
  
      //convert path to NSURL
      NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString];
  
      NSError* error;
      NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]);
          //declare a cg source reference
          CGImageSourceRef  sourceRef;
  
          //set the cg source references to the image by passign its url path
          sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL);
  
          //set a dictionary with the image metadata from the source reference
          metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
  
          NSLog(@"%@", metadata);
  
          [filePathURL release];
  
  
  } else {
  
      [self showAlert:@"I cannot find this file."];
  }
  
  [fileManager release];
  
  }
  </code></pre>
  
  <p>I'm guessing the problem here is the CFURLREF in CGImageSourceCreateWithURL. Instead of NSURL should I be using something else? </p>
  
  <p>Thanks</p>
  
  <p>Here's the path I am passing (logged from filePathURL): file://localhost/Volumes/STORAGE%20SVR/Illustration-Wofford/Illustration%20Pickup/Archive/AL013111_IL_Communication.eps</p>