Serialize and deserialize instances of your types with implicit or customized encoding.
Encoding, Decoding, and Serialization
Topics
Custom Encoding and Decoding
Make your data types encodable and decodable for compatibility with external representations such as JSON.
typealias Codable
A type that can convert itself into and out of an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Coding Key
A type that can be used as a key for encoding and decoding.
struct Coding User Info Key
A user-defined key for providing context during encoding and decoding.
Encoders and Decoders
protocol Encoder
A type that can encode values into a native format for external representation.
protocol Decoder
A type that can decode values from a native format into in-memory representations.
enum Encoding Error
An error that occurs during the encoding of a value.
enum Decoding Error
An error that occurs during the decoding of a value.
Encoding Containers
protocol Single Value Encoding Container
A container that can support the storage and direct encoding of a single non-keyed value.
struct Keyed Encoding Container
A concrete container that provides a view into an encoder’s storage, making the encoded properties of an encodable type accessible by keys.
protocol Keyed Encoding Container Protocol
A type that provides a view into an encoder’s storage and is used to hold the encoded properties of an encodable type in a keyed manner.
protocol Unkeyed Encoding Container
A type that provides a view into an encoder’s storage and is used to hold the encoded properties of an encodable type sequentially, without keys.
Decoding Containers
struct Keyed Decoding Container
A concrete container that provides a view into a decoder’s storage, making the encoded properties of a decodable type accessible by keys.
protocol Single Value Decoding Container
A container that can support the storage and direct decoding of a single nonkeyed value.
protocol Keyed Decoding Container Protocol
A type that provides a view into a decoder’s storage and is used to hold the encoded properties of a decodable type in a keyed manner.
protocol Unkeyed Decoding Container
A type that provides a view into a decoder’s storage and is used to hold the encoded properties of a decodable type sequentially, without keys.
See Also
Tools for Your Types
Use your custom types in operations that depend on testing for equality or order and as members of sets and dictionaries.
Allow values of your type to be expressed using different kinds of literals.