I try to migrate delegate of DifficultyViewDelegate to observable. This is my DifficultyViewDelegate :
@objc protocol DifficultyViewDelegate: class {
func leve
Try use PublishSubject
:
DifficultyView:
class DifficultyView: UIView {
var levelDidIncrease = PublishSubject()
var levelDidDecrease = PublishSubject()
@IBAction func decreaseLevel(_ sender: Any) {
levelDidDecrease.onNext()
}
@IBAction func increaseLevel(_ sender: Any) {
levelDidIncrease.onNext()
}
}
And then:
var difficultyView = DifficultyView()
difficultyView.levelDidDecrease.asObservable()
.subscribe(onNext: {
print("did decrease")
})
.addDisposableTo(disposeBag)
difficultyView.decreaseLevel(theSender) // <- THIS line performs the side effect