Reputation: 2021
I am working in a project using Reactive Cocoa 4.0 and MVVM(swift 2.0).In view model I have string that will update according to the textfield changes,but i need to update that textfield if the string changes.Is it possible for two way binding between textfield and string(ageString).
txtAge.rac_textSignal() ~> RAC(objViewModel, "ageString")
Upvotes: 1
Views: 1208
Reputation: 6377
You can try code below:
viewModel.ageString.producer
.skipRepeats { [weak self] in
$1 == self?.txtAge.text
}.startWithNext { [weak self] in
self?.txtAge.text = $0
}
viewModel.ageString <~ txtAge.rac_textSignal()
.toSignalProducer()
.map { ($0 as? String) ?? "" }
.flatMapError { _ in SignalProducer<String, NoError>.empty }
Upvotes: 4
Reputation: 939
Before RAC 2.x you could use RACChannel
s, which offered this functionality (you can subscribe to each channel terminal and be notified when new values arrive).
Channels and terminals haven't been ported to RAC 2.x, so today there is no two-way binding in RAC, but it shouldn't be a big deal as you can always be able to find a different (imho better) approach.
For more details you can find many threads about this topic in the framework's issues on github, such as:
Upvotes: 0