I want to create a protocol that inherits from UICollectionViewDataSource and use a protocol extension to provide a default implementation of the required UICollectionViewDataSource methods. However, when I try to declare a class that conforms to this protocol the compiler says Type 'MyClass' does not conform to protocol UICollectionViewDataSource'.
protocol MyDataSource : UICollectionViewDataSource {
var values: [String] { get }
}
extension MyDataSource {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = UICollectionViewCell() // TODO: dequeue
// TODO: configure cell ...
return cell
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.values.count
}
}
class MyClass : NSObject, MyDataSource {
var values = [String]()
}
I have also tried declaring the extension as the following, but still receive the same compiler error:
extension UICollectionViewDataSource where Self : MyDataSource
I have even tried expanding this to all UICollectionViewDataSources to see if inheritance part alone would work, but no dice—same error.
extension UICollectionViewDataSource