title: Handle NSButton click programmatically
body: <p>I'm attempting to make a subclassed <code>NSButton</code> handle a click event with no luck.</p>
  
  <p>To this point I have been customizing the <code>drawRect</code> functions in my views to get custom looks and drawing these views programmatically.  To this end, I have essentially orphaned my usage of the Interface builder (simply to avoid its sheer complexity).</p>
  
  <p>Is there a way for me to assign a click (or mouseDown in this scenario) handler programmatically, this doesn't seem to be working</p>
  
  <pre><code>class MainButton: NSButton {
  
      override func mouseDown(theEvent: NSEvent!) {
          let alert = NSAlert()
          alert.messageText = "Title"
          alert.runModal()
      }
  
      override func drawRect(rect: NSRect) {
          super.drawRect(rect)
  
          let circle : NSBezierPath = NSBezierPath(
              roundedRect: rect, xRadius: rect.size.width / 2,
              yRadius: rect.size.height / 2
          )
  
          circle.lineWidth = 2
  
          NSColor(calibratedWhite: 0.2, alpha: 1).setStroke()
          circle.stroke()
      }
  }
  </code></pre>
  
  <p>Here is <a href="https://gist.github.com/jondavidjohn/0185612b74b9f674fdf0" rel="nofollow">a full gist of the app for context if needed</a>.</p>