3

I want to model the following scenario using ReactiveCocoa in swift.

class A{
   let flagSignalProducer = A Signal Producer
   someSignal.takeUntil(a signal that I can trigger manually which is created out of flagSignalProducer).subscribeNext{ (_) in

   }
}

How can I create the Signal Producer and use the signal as takeUntil input signal and trigger the signal later manually. Am I doing it right way?

Swift Hipster
  • 1,604
  • 3
  • 16
  • 24

1 Answers1

2

to make a signal that can emit manually you can use Signal<(), NoError>.pipe() to get a reference to the signal's "observer", which will allow you to manually send events on the signal.

let (flagSignal, flagObserver) = Signal<(), NoError>.pipe()
someSignal.takeUntil(flagSignal).observeNext { _ in

}

//somewhere else, trigger the signal manually with the Observer
flagObserver.sendNext(())
flagObserver.sendCompleted() //complete the signal and free memory 

and if you need to convert your flagSignal to a SignalProducer for some reason, there is a SignalProducer constructor for that,

let flagSignalProducer = SignalProducer(signal: flagSignal)
Evan Drewry
  • 794
  • 6
  • 17