Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is [UITextField rac_newTextChannel] used to two-way bind UITextField text to a model object in ReactiveCocoa?

Say I have the following:

UITextField *textField = [[UITextField alloc] init];

and a model object:

JSModel *model = [[JSModel alloc] init];

The following will give me a two-way binding (perhaps there are disadvantages with this approach that I'm not seeing?):

RAC(model, text) = textField.rac_textSignal;
RAC(textField, text) = RACObserve(model, text);

How can [UITextField rac_newTextChannel] be used to achieve this two-way binding?

like image 915
codeperson Avatar asked Mar 18 '14 04:03

codeperson


1 Answers

Something like:

RACChannelTerminal *textFieldTerminal = [self.textField rac_newTextChannel];
RACChannelTerminal *modelTerminal = RACChannelTo(self.model, text);
[modelTerminal subscribe:textFieldTerminal];
[[textFieldTerminal skip:1] subscribe:modelTerminal];
like image 182
joshaber Avatar answered Oct 18 '22 05:10

joshaber