(也可以在GitHub上公开评论来自ReactiveCocoa的人.)
我在一个非常简单的尝试ReactiveCocoa RACTest(源是在GitHub上)应用程序试图通过实际使用它坚定了我的理论认识.
我想,我有一个RACChannel
,它提供了一个ed l值和我指定的任何参数之间的双向绑定.RAC()
RACChannel
我的用法如下:
// Map the ticker's accumulationEnabled property to self.paused. RAC(self, paused) = [RACChannelTo(_ticker, accumulateEnabled) deliverOn:[RACScheduler mainThreadScheduler]];
我看到流动的变化的一个方向,从_ticker.accumulateEnabled
到self.paused
,但变化self.paused
不会流回_ticker
.
我误解了RACChannel
吗?它有什么用,这怎么不是预期的用途?
我误解了如何使用RACChannel
.RACChannelTo
在作业的两侧使用按预期工作:
RACChannelTo(self, paused) = RACChannelTo(_ticker, accumulateEnabled);
更改的主线程交付self.paused
有点复杂,但并不可怕:
RACChannelTerminal *accumulateChannel = RACChannelTo(_ticker, accumulateEnabled); RAC(self, paused) = [accumulateChannel deliverOn:RACScheduler.mainThreadScheduler]; [[RACObserve(self, paused) skip:1] subscribe:accumulateChannel];
(我仍然试图理解为什么skip:1
是必要的,但没有它,RAC会使堆栈爆炸,所以我按照GitHub问题保留它.)