Use of unresolved operator '<~'

社会主义新天地 提交于 2019-12-11 04:56:47

问题


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.


回答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 <~ .



来源:https://stackoverflow.com/questions/41155298/use-of-unresolved-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!