I know about protocols and protocol extensions being the best way to emulate abstract classes, but what I want to do needs real abstract classes I think.
I want a BaseCollectionViewCell
and a BaseCollectionViewSource
that work together. You'd pass an array to a subclass of the BaseCollectionViewSource
and implement a method that returns a reuse identifier. The cell would be instantiated by the BaseCollectionViewSource
and have a method setData
that would be overridden in the concrete collectionViewCell.
What I practically want to do is this:
abstract class WRBaseCollectionViewCell: UICollectionViewCell {
abstract func setData(_ data: AnyObject)
}
But I can't emulate this with Swift (I think). Protocols can't inherit from classes and there is no dynamic dispatch, which kills my idea for everything to be overridable.
Does anyone have an idea how to do this? A factory maybe? I want to make this as easy as possible to implement a new collectionView.