使用未解析的类型 MutableProperty

Use of unresolved type MutableProperty

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

  class LoginViewModel {

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

    }

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

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

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

要监视 textField/textView 值的更改,此代码适用于我:

passwordTF.reactive.continuousTextValues.observeValues({ print("the new value is \([=10=]!)") })

控制台日志如下:

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 \([=12=]!)") })

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

the new value is qwer