我已经定义:
let currentHours:Variable<Float> = Variable(0.0) let currentRate:Variable<Float> = Variable(0.0)
我想通过combineLatest做出一个可观察的总结这两个价值:
Observable.combineLatest(currentHours,currentRate,{ (h,r) -> Float in return Float(h+r) })
我也试试:
let c = Observable.combineLatest(currentHours,currentRate) { $0 + $1 }
我总是得到编译错误.
谢谢
解决方法
尝试这个:
let currentHours:Variable<Float> = Variable(0.0) let currentRate:Variable<Float> = Variable(0.0) let hoursAndRate = Observable.combineLatest(currentHours.asObservable(),currentRate.asObservable()){ return $0 + $1 }
正如你可以看到的关键是将currentHours和currentRate作为Observables在函数参数中传递.