[UITextField rac_newTextChannel]如何将UITextField文本双向绑定到ReactiveCocoa中的模型对象?

时间:2014-03-18 04:35:27

标签: objective-c reactive-cocoa

说我有以下内容:

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

和模型对象:

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

以下内容将给我一个双向约束(也许这种方法存在缺点,我没有看到?):

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

如何使用[UITextField rac_newTextChannel]来实现这种双向绑定?

1 个答案:

答案 0 :(得分:11)

类似的东西:

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