日々精進

新しく学んだことを書き留めていきます

ReactiveCocoaでTwo way binding

追記:下記は間違いで、正しくは2014-08-03 - 日々精進参照。


昔はRACBindを使ってやってたけど、バージョン2.3.1ではTwo way bindingのやり方が変わったっぽい。
以下のように書くとできる。

// RACBind returns a following terminal
RACChannelTerminal *modelTerminal = RACChannelTo(model, property);
// UI category methods return a leading terminal
RACChannelTerminal *textFieldTerminal = [textField rac_newTextChannel];

[modelTerminal subscribe:textFieldTerminal];
[textFieldTerminal subscribe:modelTerminal];

まだRACChannelToとかが何やってるかわかってないから勉強しないとなぁ。
参考:Two-way binding (example) · Issue #918 · ReactiveCocoa/ReactiveCocoa · GitHub