Question

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?

Was it helpful?

Solution

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).

OTHER TIPS

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:?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top