Search code examples
objective-creactive-cocoa

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?


Solution

  • Something like:

    RACChannelTerminal *textFieldTerminal = [self.textField rac_newTextChannel];
    RACChannelTerminal *modelTerminal = RACChannelTo(self.model, text);
    [modelTerminal subscribe:textFieldTerminal];
    [[textFieldTerminal skip:1] subscribe:modelTerminal];