title: How to quit cocoa app when windows close?
body: <p>I need to quit Cocoa App when I click the red button on upper left.</p>
  
  <p><img src="https://i.stack.imgur.com/hueHQ.png" alt="enter image description here"></p>
  
  <p>I found <a href="http://forums.macrumors.com/archive/index.php/t-105229.html" rel="noreferrer">this</a> page saying </p>
  
  <blockquote>
    <p>So what you need to do first is have the window you want to close be
    connected  to an IBOutlet in the nib. For this example i connected the
    window to an  outlet named "mainWindow".</p>
  </blockquote>
  
  <p>How can I do this? I found Windows in xib file, but how can I connect it to an IBOutlet in the nib?</p>
  
  <p>Or, is there any way to quit the cocoa app clicking red button?</p>
  
  <h2>EDIT</h2>
  
  <p>I should have put the code in the <code>automatically generated delegate file</code>.</p>