我想要的是自动实现某些 NSObjectProtocol 的委托方法符合某些协议,但我很努力,没有完成。
演示在下面
更新更准确
==================================================== ========================
我有一个协议PagedLoadable
来获取collectionView需要什么的信息,然后extension NSObjectProtocol where Self: Delegatable
,自动配置对象实现PagedLoadable
protocol PagedLoadable {
var count: Int { get }
}
protocol Delegatable: UICollectionViewDelegate, UICollectionViewDataSource {
}
extension PagedLoadable where Self: Delegatable {
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return count
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = UICollectionViewCell()
return cell
}
}
class vc: UIViewController {
}
extension vc: PagedLoadable {
var count: Int {
return 1
}
}
extension vc: Delegatable {
}