问题
I am trying to write an Encoder
/Decoder
pair that wraps an given Encoder
/Decoder
. The goal of this wrapper is to successfully handle cyclic references (which neither JSONEncoder
nor PropertyListEncoder
do), and delegate the actual encoding/decoding to the wrappded encoder.
I was surprised to learn that neither JSONEncoder
nor PropertyListEncoder
conform to Encoder
and similarly, their Decoder
counterparts don't conform to Decoder
!
This seems bizarre. If these two types don't conform, then what's the point of the Encoder
protocol? Looking at the source, I can see that internally, _JSONEncoder
conforms, but it's fileprivate
.
So is there no hope? Is there really no way to generically wrap an Encoder
like JSONENcoder
or PropertyListEncoder
?
来源:https://stackoverflow.com/questions/48123983/jsonencoder-and-propertylistencoder-dont-conform-to-encoder