美文网首页
rx计算器源码

rx计算器源码

作者: zzzzzzzgk | 来源:发表于2017-03-17 21:54 被阅读0次
            Observable.from(commands)
                .merge()
                .scan(CalculatorState.CLEAR_STATE) { a, x in
                    return a.tranformState(x)
                }
                .debug("debugging")
                .subscribe(onNext: { [weak self] calState in
                    self?.resultLabel.text = calState.inScreen
                    switch calState.action {
                    case .operation(let operation):
                        switch operation {
                        case .addition:
                            self?.lastSignLabel.text = "+"
                        case .subtraction:
                            self?.lastSignLabel.text = "-"
                        case .multiplication:
                            self?.lastSignLabel.text = "x"
                        case .division:
                            self?.lastSignLabel.text = "/"
                        }
                    default:
                        self?.lastSignLabel.text = ""
                    }
                })
                .addDisposableTo(disposeBag)
    

    相关文章

      网友评论

          本文标题:rx计算器源码

          本文链接:https://www.haomeiwen.com/subject/cahnettx.html