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

时间:2021-10-09 08:13:28

I'm new to Reactive Programming. I have gone through the documentation of Reactive Cocoa but couldn't realize the differences between RACAble(), RACObserve() and RACBind().

我是Reactive Programming的新手。我已经阅读了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. If I am not correct then please correct me in this regard.

我认为RACAble()被RACObserve()替换为一些选项/参数。如果我不对,请在这方面纠正我。

Is RACObserve() skip: similar to RACAble()?

是否RACObserve()跳过:类似于RACAble()?

1 个解决方案

#1


34  

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. 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.

我认为这里引起混淆的一个重要原因是,3个月前ReactiveCocoa团队发布了v2.0,它有很多重大变化。这是一个很好的发布 - 并且有一些惊人的功能,但它确实意味着你在网上找到的大部分信息现在已经过时了。

To your specific points:

针对您的具体要点:

  1. RACAble has been replaced with RACObserve
  2. RACAble已被RACObserve取代
  3. RACBind has been replaced with RACChannelTo
  4. 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. It is a handy replacement for KVO.

RACObserve用于从对象和键路径创建信号,换句话说,它允许您获取常规属性并将它们“提升”到ReactiveCocoa世界中。它是KVO的便捷替代品。

RACChannelTo provides a mechanism for two-way binding. 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.

RACChannelTo提供双向绑定机制。换句话说,您可以保持两个属性同步。一个很好的例子是,如果你想在视图控制器或某个模型类中拥有一个绑定到UIKit控件上的属性的属性。

Another macro you will probably come across is RAC, this provides one-way binding. In other words it will set the value of the given property based on the latest value from a signal.

您可能遇到的另一个宏是RAC,它提供单向绑定。换句话说,它将根据信号的最新值设置给定属性的值。

#1


34  

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. 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.

我认为这里引起混淆的一个重要原因是,3个月前ReactiveCocoa团队发布了v2.0,它有很多重大变化。这是一个很好的发布 - 并且有一些惊人的功能,但它确实意味着你在网上找到的大部分信息现在已经过时了。

To your specific points:

针对您的具体要点:

  1. RACAble has been replaced with RACObserve
  2. RACAble已被RACObserve取代
  3. RACBind has been replaced with RACChannelTo
  4. 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. It is a handy replacement for KVO.

RACObserve用于从对象和键路径创建信号,换句话说,它允许您获取常规属性并将它们“提升”到ReactiveCocoa世界中。它是KVO的便捷替代品。

RACChannelTo provides a mechanism for two-way binding. 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.

RACChannelTo提供双向绑定机制。换句话说,您可以保持两个属性同步。一个很好的例子是,如果你想在视图控制器或某个模型类中拥有一个绑定到UIKit控件上的属性的属性。

Another macro you will probably come across is RAC, this provides one-way binding. In other words it will set the value of the given property based on the latest value from a signal.

您可能遇到的另一个宏是RAC,它提供单向绑定。换句话说,它将根据信号的最新值设置给定属性的值。