我正在使用 ReactiveSwift 创建一个包含字典的结构。我想听一下字典的变化。
struct Model {
let a: MutableProperty<[String: Int]> = MutableProperty([:])
}
但是,我很难理解如何将此属性绑定(bind)到监听器。我想做一些类似的事情:
textView.reactive.text <~ model.a["key"]
有没有办法将字典保存在可变属性中?
最佳答案
只有 MutableProperty 关联值(在您的情况下为字典)才能绑定(bind)到绑定(bind)目标,而不是字典中的值。这意味着您不能使用 <~
字典中的值的运算符。您需要执行以下操作:
model.a.producer.startWithValues { [weak textView] value in
textView?.text = value["key"]
}
关于swift - ReactiveSwift 中包含字典的 MutableProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42507770/