DataSource methods with RACSignals

好久不见. 提交于 2019-12-12 01:44:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!