let me start by saying that I have already implemented Decodable which decodes JSON into several objects with these two Integer values:
public class ARBufferData: DecoderUpdatable {
private var previousStation: Int
private var numberOfElements: Int
func update(from decoder: Decoder) throws {
//Still needs work
}
}
What I am now trying to achieve is making the created objects updatable so that when a value in the JSON changes (e.g. numberOfElements) only the value is changed in the corresponding object. I believe this guide can enable me to do it, but I am having trouble implementing it: Understanding and Extending Swift 4’s Codable
This is the extension of KeyedDecodingContainer:
extension KeyedDecodingContainer {
func update<T: DecoderUpdatable>(_ value: inout T, forKey key: Key, userInfo: Any) throws {
let nestedDecoder = NestedDecoder(from: self, key: key)
try value.update(from: nestedDecoder)
}
}
The reason this would be helpful is that I can then set a property observer on that value and trigger a redraw of the visualisation.
I would be very grateful, if anyone can help or point me in the right direction.
Thank you!
Cheers