title: MacOS Swift NSTableView with NSTokenFieldCell tracking which column drag started from
body: <p>I have a simple test program that has a 2 column NSTableView (View based), both columns have their cells set to NSTokenFieldCell.
  I also have a NSTokenField in this controller</p>
  <p>I want to be able to drag and drop tokens from the table to the field.
  When I have 1 column this is working well.
  Now I have 2 columns I need to know which token to add to the field</p>
  <p>Sample code:</p>
  <pre><code>
  class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate, NSTokenFieldDelegate {
  
      @IBOutlet weak var tableView: NSTableView!
      @IBOutlet weak var tokenField: NSTokenField!
  
  let tokens = [&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;,&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;,&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;,&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;,&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;,&quot;tok1&quot;,&quot;tok2&quot;,&quot;tok3&quot;]
      let tokens2 = [&quot;image&quot;,&quot;date&quot;,&quot;time&quot;,&quot;folder&quot;]
      override func viewDidLoad() {
          super.viewDidLoad()
  
     }
  
      override var representedObject: Any? {
          didSet {
          // Update the view, if already loaded.
          }
      }
  
   func numberOfRows(in tableView: NSTableView) -&gt; Int {
          return max(tokens.count,tokens2.count)
      }
  
      func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -&gt; NSView? {
          guard let vw = tableView.makeView(withIdentifier: tableColumn!.identifier, owner: self) as? NSTableCellView else {
              return nil
          }
          if tableColumn?.title == &quot;Tokens&quot; {
              vw.textField?.stringValue = tokens[row]
          }
          else
          {
              if row &lt; tokens2.count {
                  vw.textField?.stringValue = tokens2[row]
              }
              else {
              vw.textField?.stringValue = &quot;&quot;
              }
          }
          return vw
      }
  
  // The bit where I need help 
  
  func tableView(
          _ tableView: NSTableView,
          pasteboardWriterForRow row: Int)
          -&gt; NSPasteboardWriting?
      {
              return tokens[row] as NSString //Here I need to return tokens2[row] if a token from column 2 was dragged and dropped
            
          }
      }
  </code></pre>
  <p>What I can't figure out is which column gets the click to initiate the drag and drop
  <code>tableView.clickedColumn </code> is always -1
  None of the other functions such as this fire
  <code>func tableView(_ tableView: NSTableView, updateDraggingItemsForDrag draggingInfo: NSDraggingInfo)</code></p>
  <p>Update:
  I can get this function to fire as soon as I start the drag operation:
  <code>func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet)</code>
  <a href="https://i.stack.imgur.com/gc3mt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gc3mt.png" alt="Screen shot" /></a></p>
  <p>I've tried to capture <code>mouseDown</code> but am not having any luck with it either.
  Any pointers?</p>