2

私が望むのは、一部の NSObjectProtocol が一部のプロトコルに準拠するためのデリゲートメソッドを自動実装することですが、私は一生懸命努力しますが、それを成し遂げることはできません。

デモは下にあります

より正確な更新

================================================== =======================

PagedLoadablecollectionView が必要とする情報を取得するためのプロトコルを 1 つ取得し、次に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 {

}
4

2 に答える 2