Total beginner here, just started to learn RAC last week. Now we have Xcode 8 & Swift 3 and what worked for me before doesn't work now :-(
Last week's test project didn't build and gave errors trying to update the git submodules, so I re-created it. I used git submodule add -b master https://github.com/ReactiveCocoa/ReactiveCocoa
to install RAC and then git submodule update --init --recursive
to install the other components. I followed the instructions on the Read Me page to add the 3 frameworks to my project. After inserting import ReactiveCocoa
at the top of my ViewController file, the app built without error.
I have a UITextField, so tried this: let signal = textField.rac_textSignal()
which gave this error: Value of type 'UITextField' has no member 'rac_textSignal'
The only option offered by auto-complete was rac_lifetime
.
So now I am stuck. The "online search" sample has disappeared from the site and the documentation assumes more knowledge than I have right now. All the online & book resources I have tried are using rac_textSignal()
and the only relevant post on Stack Overflow just suggested using import ReactiveCocoa
which I am already doing.
Has everything changed as part of the great Swift 3 renaming? I tried some likely looking variations but didn't hit on anything that worked.
Am I missing an installation step? Probably the most likely cause of the problem, although I have followed the instructions. Or maybe I am just stuck in a transition phase between Swift 2 & Swift 3 and should just abandon my attempt to learn RAC for a few weeks.
Either way, I would really appreciate a return of the "online search" sample to get me going.
As stated in README (Objective-C and Swift section), those Objective-C API are splitted out to ReactiveObjC
framework. You need to add https://github.com/ReactiveCocoa/ReactiveObjC as a submodule, link the framework, then import ReactiveObjC
.
So now I am stuck. The "online search" sample has disappeared from the site and the documentation assumes more knowledge than I have right now.
That is now in ReactiveSwift's README. To make the example work, you'll need https://github.com/ReactiveCocoa/ReactiveObjCBridge too.
Thanks for the fast response, but I am now thoroughly confused.
I have found the ReactiveObjC github page and the ReadMe starts with this warning:
NOTE: This is legacy introduction to the Objective-C ReactiveCocoa, which is now known as ReactiveObjC. For the updated version that uses Swift, please see ReactiveCocoa or ReactiveSwift
So it doesn't seem like this is what I should be using.
Then there is the ReactiveObjCBridge, ReactiveCocoa, ReactiveSwift...
No idea which I should be using - I just want to use Swift and learn about Reactive programming...
Anyway, feeling that it shouldn't be necessary, I added the ReactiveObjCBridge using git submodule add -b master https://github.com/ReactiveCocoa/ReactiveObjC
.
Then I ran git submodule update --init --recursive
which appeared to download 2nd copies of Nimble & Quick into the ReactiveObjC/Carthage/Checkouts folder. Maybe that was a mistake.
Going back to my test project, I added the ReactiveObjC.xcodeproj to the project and added ReactiveObjC.framework to the embedded binaries. This time the line containing rac_textSignal()
compiled correctly, but it crashes at runtime:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField rac_textSignal]: unrecognized selector sent to instance 0x....
Is rac_textSignal()
a legacy function that I should not be using with Swift?
Is there any good online source for how to learn ReactiveCocoa/ ReactiveSwift without using the legacy ReactiveObjC?
Reactive programming has been on my to-learn list for a while now, but I am beginning to think I should stick to standard Swift and forget this adventure.
FYI, 3 of the 5 links in the Objective-C and Swift section of the README are broken.
It can be used in Swift. It is just that it is not designed for Swift.
We are planning to bring in bindings and stuff from Rex as part of the ReactiveCocoa Swift 3.0 release, and there should be a Swift equivalent rex_textSignal
. In the meantime, if you need to migrate to Swift 3.0 ASAP, you can still link ReactiveObjC and ReactiveObjCBridge (if you need to lift it as SignalProducer
).
So basically I should just wait until you have a Swift 3 release. OK, thanks for the info.
@andersio I'm running into this same issue and I was wondering if anything has been added to the newer releases of ReactiveSwift to accommodate for an apparent lack of rac_textSignal()
UI Extensions have since been added to RAC in the 5.0.0-alpha1 release.
You can use .reactive.textValues
or .reactive.continuousTextValues
on UITextField
and UITextView
.
Would greatly appreciate your opinion on this, I have the following code to wrap all of the logic in a single block of code, pressing the button pops the current view controller from the stack. How would I go by doing this now that rac_signal(for :) is not there in RAC5. I did play around with reactive.pressed and reactive.trigger but didn't get anywhere
menuButton.rac_signal(for: UIControlEvents.touchUpInside)
.subscribeNext {
[weak self] (touched) in
self!.navigationController!.popViewController(animated: true)
}
@aleuri UIControl.reactive.trigger(for:)
hands you a trigger signal (Signal<(), NoError>
).
menuButton.reactive.trigger(for: .touchUpInside)
.observeValues { [weak self] in
self?.navigationController!.popViewController(animated: true)
}
Please note that the ObjC API, e.g. RACSignal.subscribeNext
, is no longer part of ReactiveCocoa, and is now hosted in ReactiveObjC.
Most helpful comment
@aleuri
UIControl.reactive.trigger(for:)
hands you a trigger signal (Signal<(), NoError>
).Please note that the ObjC API, e.g.
RACSignal.subscribeNext
, is no longer part of ReactiveCocoa, and is now hosted in ReactiveObjC.