I am trying to create a bidirectional bind using ReactiveKit/Bond. I am trying to create the bind to the UserDefaults on my View Model, but I am having trouble figuring out how to make that happen. I tried using reactive with the keyPath that returns a DynamicSubject2<T, NoError>
but when I set the property on the View Model and use a bidirectional bind from the View Controller, it does not actually create a bidirectional bind. I actually can't tell what it is doing at all, but the data is not flowing to the UserDefaults. It only appears to be one way from UserDefaults to the View Model to the View Controller
SettingsViewModelType (Protocol for View Model)
protocol SettingsViewModelType {
var useMetric: DynamicSubject<Bool> { get }
}
Init Method for View Model
init(userDefaults: UserDefaults = UserDefaults.standard)
{
self.userDefaults = userDefaults
useMetric = self.userDefaults.reactive.keyPath("useMetric", ofType: Bool.self, context: .immediateOnMain)
}
I also tried using the method that would return a dynamic subject and let's you override the getter and setter but I am having trouble figuring out what exactly the signal is supposed to be.
useMetric = userDefaults
.reactive
.dynamicSubject(signal: <What is the Signal?> , context: .immediateOnMain, get: { (defaults) -> Bool in
return defaults.value(forKey: "useMetric") as! Bool
}) { (defaults, value) in
defaults.set(value, forKey: "useMetric")
}
I'm sure there has to be a way to set up the bidirectional bind to the UserDefaults key that I want. Any help would be greatly appreciated!