title: Detailed instruction on use of NSOpenPanel
body: <p>I want to be able to open an image in Swift. This is my first Swift project. </p>
  
  <pre><code>@IBAction func SelectFileToOpen(sender: NSMenuItem) {
      var openPanel = NSOpenPanel();
      openPanel.allowsMultipleSelection = false;
      openPanel.canChooseDirectories = false;
      openPanel.canCreateDirectories = false;
      openPanel.canChooseFiles = true;
      let i = openPanel.runModal();
      if(i == NSOKButton){
          print(openPanel.URL);
          var lettersPic = NSImage(contentsOfURL: openPanel.URL!);
          imageView.image = lettersPic;
  
      }
  }
  </code></pre>
  
  <p>Output of my <code>NSLog</code> when using the open panel </p>
  
  <pre><code>Optional(file:///Users/ethansanford/Desktop/BigWriting.png)
  fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>How can I allow the user to open a png file of interest. 
  When I specifying the same file in the code everything works well. An example of me indicating which file to open in the code without using the open file panel and acting as a user:</p>
  
  <pre><code>let pictureURl = NSURL(fileURLWithPath: "///Users/ethansanford/Desktop/BigWriting.png");
  var lettersPic = NSImage(contentsOfURL: pictureURl!);
  imageView.image = lettersPic; 
  </code></pre>
  
  <p>Is there a problem with the format of my URL or something? Any help would be appreciated.                  </p>