我定义了:
let currentHours:Variable<Float> = Variable(0.0)
let currentRate:Variable<Float> = Variable(0.0)
我想用combineLatest制作一个Observable来对这两个值求和:
Observable.combineLatest(currentHours, currentRate, { (h, r) -> Float in
return Float(h+r)
})
我也尝试:
let c = Observable.combineLatest(currentHours, currentRate) { $0 + $1 }
我总是遇到编译器错误。 感谢
答案 0 :(得分:48)
试试这个:
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 传递。