JaSHin JaSHin - 5 months ago 10
Swift Question

Getting current value and start observing on MutableProperty

I have MutableProperty. When I create new object I want to get current value of MutableProperty and start observing.

Such as:

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
}


Is it possible write it better ?

Answer

If you want to use the value immediately:

let mutableProperty = MutableProperty<Driver?>(Driver(id: 1, name: "John"))
let label = UILabel()

mutableProperty.producer.startWithNext{ driver in
     label.text = driver?.name
}
Comments