RxSwift Не удается преобразовать тип результата вызова '(_) -> Disposable' в ожидаемый тип '(_) ->

Я пытаюсь добавить headerView в collectionView с помощью RxSwift.

Я получаю эту ошибку:

Не удается преобразовать тип результата вызова '() -> Disposable' в ожидаемый тип '() ->

в этой строке:

obsHeader.asObservable().bind(to: collectionView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

Я не понимаю, как это исправить. Любая помощь?

Я размещаю здесь остальную часть кода:

struct SectionItemObject {
    let collectionViewRecommendations: UICollectionView
    let items: [SFCardViewModelListOfCardsProtocol]
}

struct SectionOfItems {
    var items: [Item]
}

extension SectionOfItems: SectionModelType {

    typealias Item = SectionItemObject

    init(original: SectionOfItems, items: [Item]) {
        self = original
        self.items = items
    }

    init(items: [Item]?) {
        self.items = items ?? [Item]()
    }
}

И это то, что я пишу в методе, который я призываю наблюдать.

let dataSource = RxCollectionViewSectionedReloadDataSource<SectionOfItems>(configureCell: { (datasource, collectionview, indexPath, i) -> UICollectionViewCell in
        let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "CardView", for: indexPath) as! CardView
        //                self.setCell(card:card,cell:cell)
        cell.lbTitle.text = "TEST"
        return cell
    }, configureSupplementaryView: { (datasource, collectionview, kind, indexPath) -> UICollectionReusableView in
        let section = collectionview.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AddNewCardCollectionHeaderView", for: indexPath) as! AddNewCardCollectionHeaderView
        section.backgroundColor = UIColor.orange
        section.collectionViewRecommendations = self.collectionViewRecommendations
        return section
    } )

let item = SectionItemObject(collectionViewRecommendations: self.collectionViewRecommendations!, items: viewModelProtocol.searchedCards.value)
let obsHeader = Variable(SectionOfItems(items: [item]))

obsHeader.asObservable().bind(to: collectionView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

person Andrea.Ferrando    schedule 02.02.2018    source источник
comment
Я попытался скомпилировать ваш код, в моем случае он жалуется не на упомянутую вами строку, а на объявление dataSource (аргумент передается вызову, который не принимает параметров).   -  person Maxim Volgin    schedule 02.02.2018
comment
Я отредактировал код, скопировав именно то, что компилирую. Вы можете проверить сейчас? Спасибо!!   -  person Andrea.Ferrando    schedule 02.02.2018


Ответы (1)


Бьюсь об заклад, что ваш obsHeader должен быть введен как Variable<[SectionOfItems]>

Так что просто сделай это

let obsHeader = Variable([SectionOfItems(items: [item])])
person Timofey Solonin    schedule 02.02.2018
comment
Спасибо! да было такое! - person Andrea.Ferrando; 02.02.2018