简体   繁体   English

Reactive Cocoa中RACAble(),RACObserve()和RACBind()之间的区别

[英]Difference between RACAble(), RACObserve() and RACBind() in Reactive Cocoa

I'm new to Reactive Programming. 我是Reactive Programming的新手。 I have gone through the documentation of Reactive Cocoa but couldn't realize the differences between RACAble() , RACObserve() and RACBind() . 我已经阅读了Reactive Cocoa的文档,但无法实现RACAble()RACObserve()RACBind()之间的差异。

Please, help ,me in understanding the aspects by some example code snippets. 请帮助我,通过一些示例代码片段来理解方面。

I think the RACAble() is replaced with RACObserve() with some options/arguments. 我认为RACAble()被替换为RACObserve()有一些选项/参数。 If I am not correct then please correct me in this regard. 如果我不对,请在这方面纠正我。

Is RACObserve() skip: similar to RACAble() ? 是否RACObserve() skip:类似于RACAble()

I think one big source of confusion here is that 3 months ago the ReactiveCocoa team released v2.0 , which had quite a few breaking changes. 我认为这里引起混淆的一个重要原因是,3个月前ReactiveCocoa团队发布了v2.0 ,其中有很多重大变化。 This was a great release - and has some amazing features, but it does mean that much of the information you will find on the web is now out-dated. 这是一个很棒的版本 - 并且有一些惊人的功能,但它确实意味着你在网上找到的大部分信息现在已经过时了。

To your specific points: 针对您的具体要点:

  1. RACAble has been replaced with RACObserve RACAble已被RACObserve取代
  2. RACBind has been replaced with RACChannelTo RACBind已被RACChannelTo取代

RACObserve is used to create a signal from an object and a keypath, in other words it allows you to take regular properties and 'lift' them into the ReactiveCocoa world. RACObserve用于从对象和键路径创建信号,换句话说,它允许您获取常规属性并将它们“提升”到ReactiveCocoa世界中。 It is a handy replacement for KVO. 它是KVO的便捷替代品。

RACChannelTo provides a mechanism for two-way binding. RACChannelTo提供双向绑定机制。 In other words you can keep two properties synchronised. 换句话说,您可以保持两个属性同步。 A good example of this is if you want to have a property in your view controller, or some model class, bound to a property on a UIKit control. 一个很好的例子是,如果要在视图控制器或某个模型类中拥有绑定到UIKit控件上的属性的属性。

Another macro you will probably come across is RAC , this provides one-way binding. 您可能会遇到的另一个宏是RAC ,它提供了单向绑定。 In other words it will set the value of the given property based on the latest value from a signal. 换句话说,它将根据信号的最新值设置给定属性的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM