About the best way to implement this, I am thinking about
-
Adding
mutating func skip() throws
to theUnkeyedDecodingContainer
protocol in Codable.swift.yb -
Adding and extension to the
UnkeyedDecodingContainer
protocol in Codable.swift.gyb doing the same thing I currently do, decoding an empty struct
// Default implementation of skip() in terms of decoding an empty struct
struct Empty: Decodable { }
extension UnkeyedDecodingContainer {
public mutating func skip() throws {
_ = try decode(Empty.self)
}
}
The empty struct does not seem very elegant but this should be a reasonable default implementation that should work for the JSONDecoder
and some other decoders.
Any custom decoder can then implement the method in specific way as needed or maybe throw a fatalerror
if this method is really not suitable for it.