Search code examples
swift4reactive-cocoareactive-swift

How to use rac_signalForControlEvents


How can I convert same method "rap_signalForControlEvents" to last working ReactiveCocoa Version?

Method example

I'm trying to build a example of the book Reactive programming with swift, but when I implemented the same method it doesn't work.

I've changed the reactiveCocoa version to the same of the book example but I think it's not updated for the new Swift Version.


Solution

  • I'm not sure how old the version you're using is, but at some point the library was split into two separate modules:

    1. ReactiveSwift for the general reactive primitives and operators.
    2. ReactiveCocoa for reactive integration with Cocoa.

    So first make sure you have both of those libraries in your project. Then you can create a control event signal like this:

    cell.addButton.reactive.controlEvents(.touchUpInside)
        .observeValues { _ in
            // Handle the button press here
        }