Skip to content

Instantly share code, notes, and snippets.

@stigi
Created February 4, 2014 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigi/8805151 to your computer and use it in GitHub Desktop.
Save stigi/8805151 to your computer and use it in GitHub Desktop.
- (void)bindFormCell:(MYFormCell *)cell toViewModel:(MYFormViewModel *)viewModel withKeyPath:(NSString *)keyPath
{
// signal passing in cell as an observer will complete the signal when cell is dealloced
// (as well as (read "OR") when viewModel is dealloced)
RACSignal *textInputSignal = [viewModel rac_valuesForKeyPath:keyPath observer:cell];
@weakify(cell);
RACDisposable *inputDisposable = [textInputSignal subscribeNext:^(NSString *text) {
@strongify(cell);
cell.textField.text = text;
}];
RACSignal *textOutputSignal = [cell.textField rac_textSignal];
@weakify(viewModel);
RACDisposable *outputDisposable = [textOutputSignal subscribeNext:^(NSString *text) {
@strongify(viewModel);
[viewModel setValue:text forKey:keyPath];
}];
// whenever the cell is reused unbind those signals
[[[cell rac_prepareForReuseSignal] take:1] subscribeNext:^(id x) {
[inputDisposable dispose];
[outputDisposable dispose];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment