RACChannel介绍

RACChannel可以被看成是一个由两个并行工作的signal组成的双向连接。例如,当连接一个view和一个model时有如下模型:
Model View
leadingTerminal ------> followingTerminal
leadingTerminal <------ followingTerminal

Model的初始值以及后面值的改变都会发送到leadingTerminal,由followingTerminal的订阅者所接收。
同样,不论何时view的值发生了改变,修改后的值会发送到followingTerminalleadingTerminal中的model会收到。但是,view的初始值不回被收到。

RACChannelTo宏

RACChannelTo()作为右值表达式时,它返回一个RACChannelTerminal,可以用来观测特定属性的改变。如果作为左值,那么右值必须是一个RACChannelTerminal值。两个RACChannelTerminal互相订阅,左边的属性值会立刻发送到右边的信号,然后接下来值的改变都会发给对方。

在使用两个textField进行双向绑定测试时发现了这么一个现象:

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的值以及后续的KVO通知都是发送给channel的following terminal的订阅者。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容