Using ReactiveCocoa, there seem to be two ways to have subscribers receive the same values from a signal, rather than re-triggering whatever operation generates those values: Vi
Actually, they're not mutually exclusive, and can even be used together.
The main purpose of RACMulticastConnection is to subscribe to a base signal, and then multicast that subscription to any number of other subscribers, without triggering the base signal's side effects multiple times.
RACMulticastConnection
accomplishes this by sending values to a private RACSubject, which is exposed via the connection's signal property. Subscribers attach to the subject (which doesn't cause any side effects), and the connection forwards all of the base signal's events there.
There are a few different methods to create a connection:
RACSubject
. This subject will not replay previous values to new subscribers.RACReplaySubject
here.RACReplaySubject
, and then also automatically connecting to it.If in doubt, -replayLazily
will probably do what you want, because it saves all values and only triggers any side effects (or starts any work) when the returned signal receives a subscription.