Has anybody made self updating mutable table view based on a RACSignal?

1.3k views Asked by At

Now that there's a full support for KVO, has anybody made a mutable table view that takes a RACSignal as its dataSource? Ideally something that doesn't require any configuration.

RACSignal *commentsSignal;
UITableView *table = [UITableView new];
table.dataSourceSignal = commentsSignal;
[self.view addSubview:table];
// No more basic config
2

There are 2 answers

5
ColinE On

Yes, I have created a 'binding helper' that binds a table view to a signal:

http://www.scottlogic.com/blog/2014/05/11/reactivecocoa-tableview-binding.html

You can use it to bind a signal to table view where the cell is defined in a nib, as shown below:

// create a cell template
UINib *nib = [UINib nibWithNibName:@"CETweetTableViewCell" bundle:nil];

// bind the ViewModels 'searchResults' property to a table view
[CETableViewBindingHelper bindingHelperForTableView:self.searchResultsTable
                        sourceSignal:RACObserve(self.viewModel, searchResults)
                        templateCell:nib];

In the above example the table view is bond to an NSArray property on a view model via RACObserve(self.viewModel, searchResults), however any RACSignal that emits an array will bind just fine.

1
Adlai Holler On

ReactiveCocoa 3.0 (currently in development) adds a category on UITableView that does just that.

I haven't updated it in a couple weeks, but I made an early podspec for it: https://gist.github.com/adlai-holler/ae321c3398d7db9a55c0