title: Drag and drop function swift OSX
body: <p>This is a bit complex but I hope that someone can help me.
  I am trying to build a drag and drop function for my OSX application. </p>
  
  <p><a href="https://i.stack.imgur.com/3zZf0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3zZf0.png" alt="enter image description here"></a></p>
  
  <p>This is how it is looking at the moment.
  So there is just a single textfield which the user can drag and drop around the view. It is simple enough with just one textfield but if there are several textfields it is getting complicated and I don't know how to approach.
  This is what I currently have:</p>
  
  <pre><code>@IBOutlet weak var test: NSTextField!
  
  @IBAction override func mouseDragged(theEvent: NSEvent) {
      NSCursor.closedHandCursor().set()
      var event_location = theEvent.locationInWindow
  
      test.frame.origin.x = event_location.x - 192
      test.frame.origin.y = event_location.y
  }
  </code></pre>
  
  <p>Test is the name of my NSTextField. I know the name of it so it is simple to move it arround. But if the user adds more textfields (see on the left pane) then I don't know how to address this textfield because I have no name of it (like "test" for the first input).</p>
  
  <p>I am adding the textfields via this code:</p>
  
  <pre><code>    let input = NSTextField(frame: CGRectMake(width, height, 100, 22))
      self.MainView.addSubview(input)
  </code></pre>
  
  <p>How can I determine which textfield (if there are multiple on the view) was selected and then move the appropriate via drag and drop?</p>
  
  <p><strong>The drag and drop is working for that single static textfield</strong></p>