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

StackOverflow https://stackoverflow.com/questions/22470478

  •  16-06-2023
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

Something like:

RACChannelTerminal *textFieldTerminal = [self.textField rac_newTextChannel];
RACChannelTerminal *modelTerminal = RACChannelTo(self.model, text);
[modelTerminal subscribe:textFieldTerminal];
[[textFieldTerminal skip:1] subscribe:modelTerminal];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top