无法在RxDataSources中推断通用参数'Self'

时间:2018-07-25 17:38:30

标签: ios swift rx-swift rx-cocoa

我正在尝试将RxDataSources https://github.com/RxSwiftCommunity/RxDataSources用于简单的TableView

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        let items = [
            CustomItem(id: 12, title: "name"),
            CustomItem(id: 22, title: "your age"),
            CustomItem(id: 77, title: "style")
        ]

        let data = Observable<[CustomItem]>.just(items)

        data.bind(to: tableView.rx.items(cellIdentifier: "CustomCell", cellType: CustomCell)) {
            index, model, cell in
            cell.questionLbl.text = model
            }
            .disposed(by: disposeBag)
    }

}

class CustomCell: UITableViewCell {
    @IBOutlet weak var questionLbl: UILabel!
}

struct CustomItem: Equatable {
    let id: Int
    let title: String

    static func == (lhs: CustomItem, rhs: CustomItem) -> Bool {
        return lhs.id == rhs.id
    }
}

我得到了这个错误:

  

无法推断出通用参数'Self'

p.s。如您所见-我将Equatable添加到了我的结构中,但它也无法正常工作。同时,如果我将自定义对象的数组更改为字符串数组,一切都会开始正常工作。

0 个答案:

没有答案