Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

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

like image 212
TryinHard Avatar asked Dec 04 '13 05:12

TryinHard


1 Answers

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.

To your specific points:

  1. RACAble has been replaced with RACObserve
  2. RACBind has been replaced with 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.

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.

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.

like image 195
ColinE Avatar answered Oct 31 '22 01:10

ColinE