【问题标题】:Use of unresolved type MutableProperty使用未解析类型 MutableProperty
【发布时间】:2016-11-25 06:19:44
【问题描述】:

我正在尝试在视图模型中声明一个属性,稍后我将绑定到视图..

  class LoginViewModel {

     let myProperty = MutableProperty("")//error here undeclared type MutableProperty

    }

我正在使用 ReactiveCocoa '5.0.0-alpha.3'。

【问题讨论】:

    标签: swift reactive-cocoa reactive-cocoa-5


    【解决方案1】:

    由于 ReactiveCocoa was split into ReactiveCocoa and ReactiveSwift,您可能需要在文件中导入 @import ReactiveSwift 以及 @import ReactiveCocoa

    另外,如果您通过 Carthage 添加 ReactiveCocoa,请不要忘记将 ReactiveSwift.framework 添加到您的项目中。

    【讨论】:

    • 谢谢..我是 RAC 的新手..你能告诉我如何打印文本字段值吗..我试过用这个但没有任何反应self.nameTextField.reactive.trigger(for: .valueChanged).map{ print("textfield value is \($0)") }
    【解决方案2】:

    要监控 textField/ textView 值的变化,此代码适用于我:

    passwordTF.reactive.continuousTextValues.observeValues({ print("the new value is \($0!)") })
    

    控制台日志如下:

    the new value is q
    the new value is qw
    the new value is qwe
    the new value is qwer
    

    还有另外一种方法可以监控编辑结束时的值:

    passwordTF.reactive.textValues.observeValues({ print("the new value is \($0!)") })
    

    控制台将结果记录在一行中:

    the new value is qwer
    

    【讨论】:

    • 谢谢..但是我不能用这个self.nameTextField.reactive.trigger(for: .editingChanged)过滤文本
    • 我正在尝试为文本字段 nshipster.com/reactivecocoa 执行此操作
    • @Costello passwordTF.reactive.continuousTextValues.filter { ($0?.characters.count)! > 3 }.observeValues { print($0!) }
    • 谢谢你能给我一个例子如何做的动作..可能是观察一个动作或做一些事情?
    • 但是为什么不调用let isValidUserName = nameTextField.reactive.continuousTextValues.filter { print( ($0?.characters.count)! > 3) return ($0?.characters.count)! > 3 }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多