Search code examples
iosrx-swift

items' produces '(Source) -> Disposable', not the expected contextual result type '(_) -> _' error with UICollectionLayout


I have a custom control which holds UICollectionView. This custom control has its own view model. I am using RXswift for MVVM design.

The view model class looks as below

class CalendarViewModel {

    public var calendarNDays = PublishSubject<[CalendarControlDayModel]>()

    struct CalendarControlDayModel {
        var date: String = ""
        var day: Int = 0
        var name: String = ""
    }

}

The custom control is called calendarView in which I am creating an instance of the above view model and setting up the binding to populate data in the collection view.

The method to set up binding in the custom control looks as below.

func setUpBinding() {

        calendarViewModel.calendarNDays.bind(to: collectionView.rx.items(cellIdentifier: cellReuseIdentifier, cellType: CalendarViewCell.self)) {  (row,calendarDay,cell) in
            cell.calendarDay = calendarDay
            }.disposed(by: disposeBag)

    }

But I am getting a compilation error for the above method that reads "items' produces '(Source) -> Disposable', not the expected contextual result type '(_) -> _"

If I define calendarNDays as a publishSubject within the custom control, it does not complain. Any hints on what is wrong here. I want to setup the binding with a property defined in view model inorder to display collection view items and inorder to conform with MVVM design pattern.


Solution

  • I suspect you have defined two CalendarControlDayModel types. One is in CalendarViewModel and the other is defined elsewhere. Check for that and report back.