[swift-evolution] Is there a simple way to go from Codable to Any and vice versa?
Youming Lin
youminglin at outlook.com
Tue Aug 22 14:31:34 CDT 2017
Hi all
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:
https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/JSONEncoder.swift#L867-L868
However, it's not public and hence not currently usable in my code without copy/pasting the source code from Foundation to my package.
Youming Lin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170822/0a8e10a9/attachment.html>
More information about the swift-evolution
mailing list