问题
Can I implement dataSource method with RACSignal that returns value.
I wan't something like this -
[self rac_signalForSelector:@selector(tableView:numberOfRowsInSection:)]{
return @10;}];
How to deal with methods that needs a return values when you work with signal?
回答1:
ReactiveCocoa, like all Reactive Extensions-based frameworks, is designed around a push-based API for operating on a series of values. That is, you have some source of values and then you use signal composition to react to the arrival of new values.
On the other hand, the "data source" pattern common to many Cocoa frameworks requires that you provide a pull-based API. That is, you have some source of values, and you make those values available to other objects by implementing query methods like -tableView:numberOfRowsInSection:
. The other objects will generally call these methods synchronously when they need to know the number of table rows in the specified section.
These two concepts are pretty much at odds with each other. It would be hard to "implement a data source using ReactiveCocoa" (though ReactiveCocoa can certainly be useful to other areas of your app).
回答2:
RAC doesn't provide the ability to define methods that return values. Instead, you must implement the method to return the appropriate value, and with that in place you can call -rac_signalForSelector:
to get a signal. Thing is, why would you want a signal for methods like numberOfRowsInSection:
?
来源:https://stackoverflow.com/questions/23492229/datasource-methods-with-racsignals