1

I am using ReactiveCocoa 5.0 alpha 3, ReactiveSwift and Swift 3

I am having issues with binding my UITextField to a MutableProperty.

In ReactiveCocoa 4, I used this:-

extension UITextField {
    func signalProducer() -> SignalProducer<String, NoError> {
        return self.rac_textSignal().toSignalProducer()
            .map { $0 as! String }
            .flatMapError { _ in return SignalProducer<String, NoError>.empty }
    }
}

viewModel.email <~ emailTextField.signalProducer()

But now in ReactiveCocoa 5, I am not able to do that. From what I understand, I am supposed to do something like this I guess:-

viewModel.email <~ emailTextField.reactive.textValues

But either it says '<~' is unresolved or textValues is not a property.

Please help me bind this.

Abhinav Nair
  • 958
  • 1
  • 8
  • 29
  • What are you trying to accomplish with the `<~`? – Brandon A Dec 15 '16 at 02:15
  • I am just trying to bind the textfield to the mutlableproperty. Am I doing something wrong? – Abhinav Nair Dec 15 '16 at 02:19
  • Did you `import ReactiveCocoa` into your extension file? – Brandon A Dec 15 '16 at 02:20
  • I am not using an extension in ReactiveCocoa 5. Because I am not able to convert the signal to SignalProducer. Actually this is my first attempt at ReactiveCocoa and I am following a demo project and trying to reproduce that in ReactiveCocoa 5 for my company project. – Abhinav Nair Dec 15 '16 at 02:22
  • In your example code above you are extending the UITextField. My question was are you importing the module for ReactiveCocoa into the class you are using that operator? – Brandon A Dec 15 '16 at 02:29
  • Yes I am but that was for ReactiveCocoa 4. I am not using the extension anymore in ReactiveCocoa 5. Or should I be doing it again here? – Abhinav Nair Dec 15 '16 at 02:30
  • Even if I try and do using the extension, (which is on a separate file) and return a signal instead of the signalProducer and do viewModel.email <~ emailTextField.signal() It still says use of unresolved operator '<~' – Abhinav Nair Dec 15 '16 at 02:33
  • I would try doing whatever you had for ReactiveCocoa 4 now with ReactiveCocoa 5. I have never used either. But the error you are getting indicates your class is unaware of this operator. Which indicates to me that you may not have imported the module. Beyond that I'm not sure either. – Brandon A Dec 15 '16 at 02:47
  • 5
    the `<~` operator is defined by the `ReactiveSwift` module. Make sure to `import ReactiveSwift` also. – Sebastian Hojas Dec 21 '16 at 10:50

1 Answers1

1

The <~ in Rac5 is a function for binding a BindingTarget with a signal, u can use it like this:

placeHolderLabel.reactive.isHidden <~
        self.reactive
        .values(forKeyPath: #keyPath(passwordTF.text))
        .map({ (value) -> Bool in
            let value = value as! String
            return !value.isEmpty
        })

or this:

let buttonEnabled = MutableProperty<Bool>(false)

button.reactive.isEnabled <~ buttonEnabled

And make sure you have imported the module ReactiveSwift in the files which you use <~ .

Shaw
  • 92
  • 5