I have defined:
let currentHours:Variable<Float> = Variable(0.0)
let currentRate:Variable<Float> = Variable(0.0)
and I would like to make an Observable with combineLatest to sum these two value:
Observable.combineLatest(currentHours, currentRate, { (h, r) -> Float in
return Float(h+r)
})
and I also try:
let c = Observable.combineLatest(currentHours, currentRate) { $0 + $1 }
I always get compiler error. thanks
Try this:
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
}
As you can see the key is in passing currentHours and currentRate as Observables in the function parameters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.