Is there any easy way to create MutableProperty from MutableProperty in Swift ReactiveCocoa 4?
I have a case that, and I want an way to create classB with classA, in which I need to setup statusB with statusA, but how to do this?
class ClassA {
var statusA = MutableProperty<T>
}
class ClassB {
var statusB = MutableProperty<U>
func getStatusB(from StatusA: T) -> U {
// .. assume this is implemented.
}
init(statusB: U) {
//...
}
convenience init(from classA: ClassA) {
self.statusB = // here how to setup this value from classA's statusA with getStatusB(from:)?
}
}
you can't make a
MutableProperty<U>directly from aMutableProperty<T>but you can make aMutableProperty<U>with initial valuegetStatusB(from: classA.statusA.value)and then bind it toclassA.statusA.signal.map(getStatusB)so all changes to theMutableProperty<T>propagate to theMutableProperty<U>, like(however for this to compile,
getStatusBcan't be an instance method ofClassBbecause you need to be able to call it before you callself.init)