I'm trying to make my Codable model work with ReactiveKit/Bond. I believe I need to conform to the PropertyProtocol and set my properties as Property types, but decoding fails. If I set var x: String
decoding doesn't fail.
What I've tried:
import Foundation
import ReactiveKit
import Bond
struct Test: Codable, PropertyProtocol {
var value: String
typealias ProperyElement = String
var x: ProperyElement = ProperyElement()
enum CodingKeys: CodingKey {
case x
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(x, forKey: .x)
}
init(from decoder: Decoder) throws {
value = ProperyElement()
let container = try decoder.container(keyedBy: CodingKeys.self)
x = try container.decode(String.self, forKey: .x)
}
}
I also tried setting up properties as an observable like this article mentions but I couldn't get the struct to conform to Codable: https://medium.com/@oleary.audio/reactivekit-and-bond-part-1-dc13a7d99f96
Anyone know how to get ReactiveKit/Bond to play nice with Codable structs/classes?