title: Swift OSX - Rearrange NSCollectionView with drag and drop not working
body: <p>I am trying to rearrange the item inside a <code>NSCollectionView</code> but it's not working. It doesn't call some delegate methods as <code>validate drop</code> and <code>accept drop</code>. It calls <code>func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -&gt; NSPasteboardWriting?</code> or <code>func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set&lt;IndexPath&gt;, to pasteboard: NSPasteboard) -&gt; Bool</code>, but after that is doesn't call the other methods.</p>
  
  <p>I think the problem is that I am bot being able to register the correct types for the drag and drop because when I move the items inside the collection view it doesn't show a place where the items can be dropped and after I drop it the items bounce back to their original places.</p>
  
  <p>Here is the code:</p>
  
  <p>FotoProdutoLojaCollectionViewItem.swift
      import Cocoa</p>
  
  <pre><code>class FotoProdutoLojaCollectionViewItem: NSCollectionViewItem {
  
      @IBOutlet weak var fotoProdutoLojaImageView: NSImageView!
      @IBOutlet weak var fotoCapaImageView: NSImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          fotoCapaImageView.isHidden = true
      }
  
  }
  </code></pre>
  
  <p>The items of the CollectionView</p>
  
  <pre><code>func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -&gt; NSCollectionViewItem {
  
          var item = NSCollectionViewItem()
  
          item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "FotoProdutoLojaCollectionViewItem"), for: indexPath)
  
          let fotosProdutoLojaCollectionViewItem = item as! FotoProdutoLojaCollectionViewItem
  
          produtoLoja?.fotos[indexPath.item].foto?.getDataInBackground(block: {
              (data: Data?, error: Error?) -&gt; Void in
  
              if error == nil {
                  fotosProdutoLojaCollectionViewItem.fotoProdutoLojaImageView.image = NSImage(data: data!)
              }
          })
  
          if produtoLoja!.fotos[indexPath.item].imagemCapa {
              fotosProdutoLojaCollectionViewItem.fotoCapaImageView.isHidden = false
          }else {
              fotosProdutoLojaCollectionViewItem.fotoCapaImageView.isHidden = true
          }
  
          return item
      }
  
  
  override func viewDidLoad() {
          super.viewDidLoad()
  
          fotosProdutoLojaCollectionView.delegate = self
          fotosProdutoLojaCollectionView.dataSource = self
          fotosProdutoLojaCollectionView.registerForDraggedTypes([NSPasteboard.PasteboardType(kUTTypeData as String)])
  
          fotosProdutoLojaCollectionView.setDraggingSourceOperationMask(.move, forLocal: true)
      }
  </code></pre>
  
  <p>Here is the <code>pasteboardWriterForItemAt indexPath</code>. I have tried all the commented lines.</p>
  
  <pre><code>func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -&gt; NSPasteboardWriting? {
  
      let pb = NSPasteboardItem()
  
      var data: Data?
      do {
          try data = produtoLoja?.fotos[indexPath.item].foto?.getData()
      } catch {
  
      }
      pb.setData(data!, forType: NSPasteboard.PasteboardType.string)
  
      return pb
  
      //return NSPasteboardItem()
      //return data as? NSPasteboardWriting
  }
  </code></pre>
  
  <p>And here is the <code>writeItemsAt indexPaths</code>.</p>
  
  <pre><code>func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set&lt;IndexPath&gt;, to pasteboard: NSPasteboard) -&gt; Bool {
  
      return true
  }
  </code></pre>