Other kinds of Codable in Swift 5? (non-JSON Coders)

Viewed 536

Does Apple/Swift 5 provide any other Codable serialization implementations out of the box outside of JSONEncoder/JSONDecoder?

I know I can write my own but I'm thinking for serializing certain things to storage, while JSONEncoder is convenient in that it's human readable I can probably compact it by serializing my objects in binary.

Any time I do a web search for Codable protocol every single article talks only about JSON like this is the only way to serialize.

1 Answers

Sure, there is PropertyListEncoder it's basically xml:

struct SomeStruct: Codable { let someProperty: String }

try? PropertyListEncoder().encode(SomeStruct(someProperty: "someValue"))
try? PropertyListDecoder().decode(SomeStruct.self, from: data)
Related