一个 Swift 4 编码器/解码器,用于将标准类型(字典,数组)映射到 Codable,以及反之亦然
假设我们有一个名为 Simple
的 Codable
类型
编码
let o = Simple(...)
let encoded = try DictionaryCoding().encode(o)
switch encoded {
case .dictionary(let d): // do something with d
default: // something went wrong, or maybe Simple is an Array?
}
解码
let d = [...] // dictionary with the RIGHT keys
let o = try DictionaryCoding().decode(Simple.self, from: d)
// o is a Simple, or there was an exception
我花时间在这篇博客文章中解释了创建该软件包的整个过程。
很久以前,我曾经使用过这样的许可,如果人们使用了代码并在现实生活中遇到了我,就必须请我喝啤酒,但世界现在更大了 😉
现在,此协议受 CC BY-SA 1.0 许可