我想要的是一些NSObjectProtocol的自動實現委託方法符合某些協議,但我努力工作,沒有完成。Swift2協議擴展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 {
}
什麼是錯誤您收到? –
類型'vc'不符合協議'UICollectionViewDataSource' – InvokerLaw
爲什麼不定義直接擴展到'Delegatable'? – findall