Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Last active November 11, 2017 14:44
Show Gist options
  • Save pgpt10/56268478e4df72dd972498fe7860a3a3 to your computer and use it in GitHub Desktop.
Save pgpt10/56268478e4df72dd972498fe7860a3a3 to your computer and use it in GitHub Desktop.
let items = coordinator.items
if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath
{
var dIndexPath = destinationIndexPath
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0)
{
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
}
collectionView.performBatchUpdates({
self.items.remove(at: sourceIndexPath.row)
self.items.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
collectionView.deleteItems(at: [sourceIndexPath])
collectionView.insertItems(at: [dIndexPath])
})
coordinator.drop(item.dragItem, toItemAt: dIndexPath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment