ECUICollectionViewMultiDelegate
Adds the ability for a collection view to have multiple delegates.
Installation
Swift Package Manager
.package(url: "https://github.com/EvanCooper9/ECUICollectionViewMultiDelegate", from: "0.1.0")Usage
Initial setup
- Create an instance of
ECUICollectionViewMultiDelegate - Set your collection view's delegate to that instance
- Add and remove as many delegates to your
ECUICollectionViewMultiDelegateinstance throughaddandremovemethods
Delegate methods that return values
Some UICollectionViewDelegate methods require a return value (i.e. collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool). When multiple delegates are involved, it's hard to decide which value to take. ECUICollectionViewMultiDelegate will attempt to reduce all of the values returned by all the delegates, via it's reductionDelegate property.
- Implement
ECReductionDelegate - Assign the
reductionDelegateproperty of yourECUICollectionViewMultiDelegateinstance and decide which value to return
Note: If
reductionDelegateisnil, the value returned will be from the last added delegate that responds to the current method. If no delegate responds to the current method, the defaultUICollectionViewDelegatevalue will be returned, as if no delegate was ever assigned.