JSONEncoder and PropertyListEncoder don't conform to Encoder?

流过昼夜 提交于 2019-12-20 02:05:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!