title: Modify stringValue of NSTextField in Swift
body: <p>I am trying to change the content of <code>NSTextField</code> in the <code>ViewController</code> by changing its <code>stringValue</code> coming from <code>AppDelegate</code>, but it gives me an error.</p>
  
  <p>The code in <code>AppDelegate</code> is:</p>
  
  <pre><code>class AppDelegate: NSObject, NSApplicationDelegate {
  
      var consoleOutput:String? = "Console Output"
  
      func executeCommand(command: String, args: [String]) -&gt; String {
  
          let task = NSTask()
          task.launchPath = command
          task.arguments = args
  
          let pipe = NSPipe()
          task.standardOutput = pipe
          task.launch()
  
          let data = pipe.fileHandleForReading.readDataToEndOfFile()
          let output:String = NSString(data: data, encoding: NSUTF8StringEncoding)!
          consoleOutput = output
          return output
      }
  }
  </code></pre>
  
  <p>It is called from the <code>ViewController</code>:</p>
  
  <pre><code>var myDelegate = NSApplication.sharedApplication().delegate! as AppDelegate
  </code></pre>
  
  <p>and the <code>NSTextField</code> is an <code>IBOutlet</code> created earlier:</p>
  
  <pre><code>@IBOutlet weak var outputText: NSTextField!
  </code></pre>
  
  <p>and tried to modify later:</p>
  
  <pre><code>outputText.stringValue = myDelegate.consoleOutput!
  </code></pre>
  
  <p>But all I get is</p>
  
  <blockquote>
    <p>fatal error: unexpectedly found nil while unwrapping an Optional value</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>