简体   繁体   中英

ReactiveCocoa: Immediately send the latest value when there's a new subscription

I have a bunch of manual RACSubject properties in a particular view model; I am calling sendNext at certain points in the code, and I want new subscribers to these signals to immediately have their subscribeNext block be called with the latest value in that signal. Is this possible?

As an example, if I am sending the values 1 -> 12 -> 42 and then down the line there's a new subscriber, I want that subscriber to get 42 straight off (and then obviously listen for more pushes when they come about).

OK so it looks like I wanted to be using the RACSubject subclass RACReplaySubject instead. Not sure how I missed that one!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM