Cannot receive event with custom DelegateProxy and Protocol

后端 未结 1 900
心在旅途
心在旅途 2021-01-26 11:44

I try to migrate delegate of DifficultyViewDelegate to observable. This is my DifficultyViewDelegate :

@objc protocol DifficultyViewDelegate: class {
  func leve         


        
1条回答
  •  不思量自难忘°
    2021-01-26 12:00

    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
    

    0 讨论(0)
提交回复
热议问题