RACChannel可以被看成是一個由兩個并行工作的signal組成的雙向連接凉泄。例如悔政,當連接一個view和一個model時有如下模型:
Model View
leadingTerminal ------> followingTerminal
leadingTerminal <------ followingTerminal
Model的初始值以及后面值的改變都會發(fā)送到leadingTerminal
弹沽,由followingTerminal
的訂閱者所接收圆恤。
同樣刃跛,不論何時view的值發(fā)生了改變蚂蕴,修改后的值會發(fā)送到followingTerminal
谨设,leadingTerminal
中的model會收到熟掂。但是,view的初始值不回被收到扎拣。
RACChannelTo宏
RACChannelTo()作為右值表達式時赴肚,它返回一個RACChannelTerminal,可以用來觀測特定屬性的改變二蓝。如果作為左值誉券,那么右值必須是一個RACChannelTerminal值。兩個RACChannelTerminal互相訂閱刊愚,左邊的屬性值會立刻發(fā)送到右邊的信號踊跟,然后接下來值的改變都會發(fā)給對方。
在使用兩個textField進行雙向綁定測試時發(fā)現(xiàn)了這么一個現(xiàn)象:
self.valueTextField.rac_newTextChannel
sends values when you type in the text field, but not when you change the text in the text field from code.
RACChannelTo(self.uiTextField, text)
sends values when you change the text in the text field from code, but not when you type in the text field.
RACKVOChannel繼承RACChannel鸥诽,通過下面方法初始化:
``` - (id)initWithTarget:(NSObject *)target keyPath:(NSString *)keyPath nilValue:(id)nilValue;```
當前key path的值以及后續(xù)的KVO通知都是發(fā)送給channel的following terminal的訂閱者商玫。