Last active
July 26, 2020 20:15
-
-
Save aheze/6cddb568c5e9a260ef1898e5662879da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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