Swift协议语法,其中Self:同时是UICollectionViewDataSource和UICollectionViewDelegate

Swift协议语法,其中Self:同时是UICollectionViewDataSource和UICollectionViewDelegate,swift,protocols,Swift,Protocols,我正在尝试创建一个协议,该协议将自动将UICollectionView添加到符合的任何UIViewController 这是我目前的代码: protocol ReusableNavigation { var actionContainer: UIView! { get } func addActionMenuCollection() } extension ReusableNavigation where Self: UICollectionViewDataSource {

我正在尝试创建一个协议,该协议将自动将UICollectionView添加到符合的任何UIViewController

这是我目前的代码:

protocol ReusableNavigation {
    var actionContainer: UIView! { get }
    func addActionMenuCollection()
}

extension ReusableNavigation where Self: UICollectionViewDataSource {
    func addActionMenuCollection() {
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()

        layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
        layout.itemSize = CGSize(width: 60, height: 60)
        let actionMenu:UICollectionView = UICollectionView(frame: self.actionContainer.frame, collectionViewLayout: layout)

        actionMenu.dataSource = self
        actionMenu.delegate = self
        actionMenu.register(UINib(nibName: "ActionCell", bundle: nil), forCellWithReuseIdentifier: "actionCell")
        actionMenu.semanticContentAttribute = UISemanticContentAttribute.forceRightToLeft
        self.actionContainer.addSubview(actionMenu)
    }
}
显然,当我试图设置actionMenu委托时,上面的代码会出错,因为self只是一个UICollectionViewDataSource

在我的一生中,我无法理解self将同时等于UICollectionViewDataSource和UICollectionViewDelegate的协议扩展的语法


可能吗?想法?

添加约束

extension ReusableNavigation where Self: UICollectionViewDataSource,  Self: UICollectionViewDelegate { ...
或符号连接

extension ReusableNavigation where Self: UICollectionViewDataSource & UICollectionViewDelegate