Skip to content

Instantly share code, notes, and snippets.

@aheze
Last active July 26, 2020 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aheze/6cddb568c5e9a260ef1898e5662879da to your computer and use it in GitHub Desktop.
Save aheze/6cddb568c5e9a260ef1898e5662879da to your computer and use it in GitHub Desktop.
func calculateWhereToPlaceComponent(component: AlphabetComponent, placeInSecondCollectionView: IndexPath) {
let componentOrderID = component.orderIdentifier
var indexPathToAppendTo = 0
for (index, singleComponent) in newBaseCollectionViewArray.enumerated() {
///We are going to check if the singleComponent's order identifier is smaller than componentOrderID.
///If it is smaller, we know we must insert the cell ONE to the right of this indexPath.
if singleComponent.orderIdentifier < componentOrderID {
indexPathToAppendTo = index + 1
}
}
///Now that we know where to append the green cell, let's do it!
newBaseCollectionViewArray.insert(component, at: indexPathToAppendTo)
let newIndexPath = IndexPath(item: indexPathToAppendTo, section: 0)
baseCollectionView.insertItems(at: [newIndexPath])
//we must remove the red cell now.
secondCollectionViewArray.remove(at: placeInSecondCollectionView.item)
secondCollectionView.deleteItems(at: [placeInSecondCollectionView])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment