title: Close button event on OS X app swift 2.2
body: <p>I am creating an OSX app with swift version 2.2. I need to execute a method when the user clicking the close button on top left corner of my app, I am new in Cocoa programming anyone now which is the event executing when clicking close button (see the image). </p>
  
  <p><img src="https://i.stack.imgur.com/DJyRQ.png" alt="Close button"></p>
  
  <p>My purpose is when i keep my app on dock it is not open after clicking close button(the black dot under app is showing after clicking close button), but in a case right click and force quit on it then clicking app on dock it will re open fine. I think by giving the below given code inside close button event will solve my problem.</p>
  
  <pre><code>NSApplication.sharedApplication().terminate(self)
  </code></pre>