title: Using Cocoa to create an icon for a folder
body: <p>In my Mac OS application, I'm prompting a user to create a new folder. I would like to apply an icon to this folder using Cocoa when it is created. Currently, to create the folder, I'm using the following code:</p>
  
  <pre><code>- (IBAction)browseFiles:(id)sender
  {
      NSOpenPanel *oPanel = [[NSOpenPanel openPanel] retain];
      [oPanel setCanChooseDirectories:YES];
      [oPanel setCanChooseFiles:NO];
      [oPanel setDelegate:self];
      [oPanel setCanCreateDirectories:YES];
      [oPanel beginSheetForDirectory:NSHomeDirectory()
                                file:nil
                               types:nil
                      modalForWindow:nil
                       modalDelegate:self
                      didEndSelector:@selector(filePanelDidEnd:
                                               returnCode:
                                               contextInfo:)
                         contextInfo:nil];
  }
  </code></pre>
  
  <p>After choosing a directory, the user clicks a confirm button that calls a function with the following method:</p>
  
  <pre><code>bool set = [[NSWorkspace sharedWorkspace] setIcon:[NSImage imageNamed:@"icon.icns"] forFile:path options:NSExcludeQuickDrawElementsIconCreationOption]; 
  </code></pre>
  
  <p>While the piece of code above does return "YES", the icon is not successfully applied to the folder. Am I doing something wrong in my code? </p>
  
  <p>Thanks.</p>