[swift-evolution] Is there a simple way to go from Codable to Any and vice versa?
youminglin at outlook.com
Tue Aug 22 14:31:34 CDT 2017
With Swift 4 Codable support, we can now do the following conversions:
1. Codable <-> Data using JSONEncoder/JSONDecoder
2. Any <-> Data using JSONSerialization
Not sure if I missed something obvious, but is there a simple way to do Codable <-> Any conversions? I can do Codable <-> Data <-> Any conversions to get the same results, but I doubt that's an efficient method to achieve my needs.
Looking through Foundation source code, I believe the fileprivate class _JSONDecoder enables the Any -> Codable conversion that I want:
However, it's not public and hence not currently usable in my code without copy/pasting the source code from Foundation to my package.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution