Search code examples
iosswiftrx-swift

Static member rx cannot be using on instance type UICollectionView


so i started learning about rxCocoa, and tried to implement it into a collectionview, I see no problem with tableview and it supposed to do the same with collectionView But somehow this error showed up.

So how exactly to use rx bind ? and why the error showed up

Thank you

my View Controller

final class ViewController: UIViewController {
    var presenter:HomePresenter?
    private lazy var collectionView:UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.minimumLineSpacing = 1
        layout.minimumInteritemSpacing = 1
        layout.itemSize = CGSize(width: (view.bounds.width/2)-2, height: 370)
        let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
        collectionView.backgroundColor = .white
        return collectionView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

// THIS IS WHERE THE ERROR STARTS
        presenter?.getProductList().bind(to: collectionView.rx.items(cellIdentifier: ProductCollectionViewCell.identifier, cellType: ProductCollectionViewCell.self){a,b,c in
            
        }).dispose(by:disposeBag)
     }

}

The Error

my presenter

    func getProductList() -> Observable<[ProductEntity]> {
        return self.interactor.getProductList()
    }

Solution

  • You have your parens in the wrong place...

    presenter?
        .getProductList()
        .bind(to: collectionView.rx.items(cellIdentifier: ProductCollectionViewCell.identifier, cellType: ProductCollectionViewCell.self)) { a, b, c in // two close parens here
    
        } // no close paren here
        .disposed(by: disposeBag)