AppleSwift 5是否提供了其他 Codable
序列化的实现,开箱即用。JSONEncoder
JSONDecoder
?
我知道我可以自己写,但是我想对于某些东西序列化到存储,虽然JSONEncoder很方便,因为它是人类可读的,我可能可以通过序列化我的二进制对象来压缩它。
每次我在网上搜索 Codable
协议,每一篇文章都只谈JSON,好像这是唯一的序列化方式。
当然,有 PropertyListEncoder
它基本上是xml。
struct SomeStruct: Codable { let someProperty: String }
try? PropertyListEncoder().encode(SomeStruct(someProperty: "someValue"))
try? PropertyListDecoder().decode(SomeStruct.self, from: data)