我正在尝试将distinctUntilChanged
与combineLatest一起使用,例如:
Observable.combineLatest(focusedCourse, infoState)
.distinctUntilChanged()
.map { focusedCourse, infoState in
// Implementation
}
.bind(to: videoSource)
.disposed(by: bag)
然而,我得到了错误:
Type '(BehaviorRelay<Course?>.Element, BehaviorRelay<InfoState>.Element)' cannot conform to 'Equatable'
我已经使Course
和InfoState
都是相等的,但仍然得到这个错误。我该怎么解决这个问题?
我不认为一个元组符合Equatable,即使它的所有元素都符合,你也必须向distinctUntilChanged
:提供相等性检查
Observable.combineLatest(focusedCourse, infoState)
.distinctUntilChanged { $0 == $1 }
.map { focusedCourse, infoState in
// Implementation
}
.bind(to: videoSource)
.disposed(by: bag)