Encoder

protocol Encoder

A type that can encode values into a native format for external representation.

Import import Swift

Instance Variables

var codingPath: [CodingKey] Required

The path of coding keys taken to get to this point in encoding.

Declaration

var codingPath: [CodingKey] { get }
var userInfo: [CodingUserInfoKey : Any] Required

Any contextual information set by the user for encoding.

Declaration

var userInfo: [CodingUserInfoKey : Any] { get }

Instance Methods

func container(keyedBy:) Required

Returns an encoding container appropriate for holding multiple values keyed by the given key type.

You must use only one kind of top-level encoding container. This method must not be called after a call to unkeyedContainer() or after encoding a value through a call to singleValueContainer()

type: The key type to use for the container. returns: A new keyed encoding container.

Declaration

func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key : CodingKey
func singleValueContainer() Required

Returns an encoding container appropriate for holding a single primitive value.

You must use only one kind of top-level encoding container. This method must not be called after a call to unkeyedContainer() or container(keyedBy:), or after encoding a value through a call to singleValueContainer()

returns: A new empty single value container.

Declaration

func singleValueContainer() -> SingleValueEncodingContainer
func unkeyedContainer() Required

Returns an encoding container appropriate for holding multiple unkeyed values.

You must use only one kind of top-level encoding container. This method must not be called after a call to container(keyedBy:) or after encoding a value through a call to singleValueContainer()

returns: A new empty unkeyed container.

Declaration

func unkeyedContainer() -> UnkeyedEncodingContainer