Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Created March 15, 2018 07:24
Show Gist options
  • Save pgpt10/a0e0fa77a56a5bbd75e21d62007beeb0 to your computer and use it in GitHub Desktop.
Save pgpt10/a0e0fa77a56a5bbd75e21d62007beeb0 to your computer and use it in GitHub Desktop.
let items = coordinator.items
var dIndexPath = destinationIndexPath
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0)
{
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
}
var sourceIndexPaths = [IndexPath]()
var destinationIndexPaths = [IndexPath]()
for item in items
{
if let sourceIndexPath = item.sourceIndexPath
{
sourceIndexPaths.append(sourceIndexPath)
destinationIndexPaths.append(dIndexPath)
self.items2.remove(at: sourceIndexPath.row)
self.items2.insert(item.dragItem.localObject as! String, at: dIndexPath.row)
dIndexPath = IndexPath(row: dIndexPath.row + 1, section: 0)
}
}
collectionView.performBatchUpdates({
if collectionView === self.collectionView2
{
collectionView.deleteItems(at: sourceIndexPaths)
collectionView.insertItems(at: destinationIndexPaths)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment