I am using ReactiveKit with their Bond extension, and I can't really figure out how to do something that feels kind of basic.
Let's say I have a User model in my app. Something like this.
class User: Codable {
var id: String
var firstName: String?
var avatar: String?
}
The content comes from a remote API, by making it confirm to Codable everything works nice and easy.
But let's also say for example that I would like a bidirectional binding from a model property to some UI state; that is not possible since none of my properties confirm to the BindableProtocol
. Or if I want to observe changes to my model's properties, this is not possible either of course.
So my question is: how do I turn my model properties in actual observable Properties, without breaking the existing User model and behavior? For example, it still needs to be Codable. Do I make a second ObservableUser
class, and then have didSet in all properties on the User
model to write changes to the ObservableUser
? And something similar on the ObservableUser
to write changes back to the User
? That seems horrible and hopefully not the recommenced way forward.