0

I'm trying to use the ReactiveCocoa library. But when I use the ReactiveCocoas flatMap function, I get an error. Does anyone know how to get around it? Maybe I'm doing something wrong?

let countValues = countEditAView.reactive.continuousTextValues

let flatMapClosure: (String?) -> SignalProducer<Int, NSError> = { (input) in 
   return SignalProducer.init(value: 3)
}

let filterClosure: (Int) -> Bool = { (input) in
  if (input < 0) {
    return false
  } else {
    return true
  }
}

let signalDisposable = countValues // <- Ambiguous reference to member 'flatMap'
  .flatMap(FlattenStrategy.concat, flatMapClosure)
  .filter(filterClosure)
  .observeValues { val in print("val = \(val )") }
SergeyBukarev
  • 1,478
  • 1
  • 12
  • 19

1 Answers1

0

You must explicitly specify the type of the return SignalProducer <Int, NSError> (value: 3)

let countValues = countEditAView.reactive.continuousTextValues

let flatMapClosure: (String?) -> SignalProducer<Int, NSError> = { (input) in 
   return SignalProducer<Int, NSError>(value: 3)
}

let filterClosure: (Int) -> Bool = { (input) in
  if (input < 0) {
    return false
  } else {
    return true
  }
}

let disposable = countValues
  .flatMap(FlattenStrategy.latest, flatMapClosure)
  .filter(filterClosure)
  .observeResult { (par) in print("result = \(par.value ?? 0 )") }
SergeyBukarev
  • 1,478
  • 1
  • 12
  • 19