title: windowWillClose and button action not called Swift
body: <p>I'm designing a mac app with Xcode 10 (beta) and I got an issue with the Preference Window Controller</p>
  
  <p>I have in my Main.storyboard a <strong>NSWindowController</strong> of custom class <strong>PreferenceWindowController</strong> with a toolbar. Here are its connections : 
  <a href="https://i.stack.imgur.com/pMjxo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pMjxo.png" alt="all NSWindowController connections"></a></p>
  
  <p>Here is the full class :</p>
  
  <pre><code>class PreferenceWindowController: NSWindowController, NSWindowDelegate {
  
  @IBAction func didClickAuthor(_ sender: Any) {
      print("author")
  }
  
  @IBAction func didClickTypo(_ sender: Any) {
      print("typo")
  }
  
  override func windowDidLoad() {
      super.windowDidLoad()
  }
  
  func windowWillClose(_ notification: Notification) {
      print("willClose")
  }
  }
  </code></pre>
  
  <p>The window is initiated via the <strong>AppDelegate</strong> class with this code : </p>
  
  <pre><code>let storyboard = NSStoryboard(name: "Main",bundle: nil)
  
      if let wc = storyboard.instantiateController(withIdentifier: "PreferenceWindowController") as? PreferenceWindowController
      {
          wc.showWindow(self)
      }
  </code></pre>
  
  <p>The window opens as expected, with the toolbar clickable, but no functions from PreferenceWindowController are called at all, neither the closing of the window, nor the clicks on the toolbar.</p>
  
  <p>I checked every connections, every class name, and I really don't know what's wrong... </p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>The solution is to store the PreferenceViewController class inside the AppDelegate class as a variable.</p>
  
  <p>My solution : </p>
  
  <pre><code>var preferenceWindowController:PreferenceWindowController? = nil
  
  @IBAction func clickPreferences(_ sender: Any) {
      if let wc = storyboard.instantiateController(withIdentifier: "PreferencesWindowController") as? PreferenceWindowController {
          let window = wc.window
          preferenceWindowController = wc
  
          wc.showWindow(self)
      }
  }
  </code></pre>
  
  <p>Thank you for helping !</p>