我有MutableProperty。当我创建新对象时,我想获取MutableProperty的当前值并开始观察。
如:
let mutableProperty = MutableProperty<Driver?>(Driver(id: 1, name: "John"))
let label = UILabel()
label.text = mutableProperty.value?.name
mutableProperty.signal.observeNext{driver in
label.text = driver?.name
}
有可能写得更好吗?
答案 0 :(得分:3)
如果您想立即使用该值:
let mutableProperty = MutableProperty<Driver?>(Driver(id: 1, name: "John"))
let label = UILabel()
mutableProperty.producer.startWithNext{ driver in
label.text = driver?.name
}