KeyedEncodingContainer

struct KeyedEncodingContainer

A concrete container that provides a view into an encoder's storage, making the encoded properties of an encodable type accessible by keys.

Inheritance KeyedEncodingContainerProtocol
Associated Types
public typealias Key = K

Initializers

init init(_:) Required

Creates a new instance with the given container.

  • parameter container: The container to hold.

Declaration

public init<Container>(_ container: Container) where K == Container.Key, Container: KeyedEncodingContainerProtocol

Instance Variables

var codingPath Required

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

Declaration

var codingPath: [CodingKey]

Instance Methods

func encode(_ value: Bool, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Bool, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: String, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: String, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Double, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Double, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Float, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Float, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Int, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Int, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Int8, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Int8, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Int16, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Int16, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Int32, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Int32, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: Int64, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: Int64, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: UInt, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: UInt, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: UInt8, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: UInt8, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: UInt16, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: UInt16, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: UInt32, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: UInt32, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: UInt64, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode(_ value: UInt64, forKey key: KeyedEncodingContainer<K>.Key) throws
func encode(_ value: T, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encode<T>(_ value: T, forKey key: KeyedEncodingContainer<K>.Key) throws where T: Encodable
func encodeConditional(_ object: T, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes a reference to the given object only if it is encoded unconditionally elsewhere in the payload (previously, or in the future).

For encoders which don't support this feature, the default implementation encodes the given object unconditionally.

  • parameter object: The object to encode.
  • parameter key: The key to associate the object with.

Declaration

public mutating func encodeConditional<T>(_ object: T, forKey key: KeyedEncodingContainer<K>.Key) throws where T: AnyObject, T: Encodable
func encodeConditional(_ object: T, forKey key: Self.Key) throws Required

Encodes a reference to the given object only if it is encoded unconditionally elsewhere in the payload (previously, or in the future).

For encoders which don't support this feature, the default implementation encodes the given object unconditionally.

  • parameter object: The object to encode.
  • parameter key: The key to associate the object with.

Declaration

public mutating func encodeConditional<T>(_ object: T, forKey key: Self.Key) throws where T: AnyObject, T: Encodable
func encodeIfPresent(_ value: Bool?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Bool?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: String?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: String?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Double?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Double?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Float?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Float?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Int?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Int?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Int8?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Int8?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Int16?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Int16?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Int32?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Int32?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: Int64?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: Int64?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: UInt?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: UInt?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: UInt8?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: UInt8?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: UInt16?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: UInt16?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: UInt32?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: UInt32?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: UInt64?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent(_ value: UInt64?, forKey key: KeyedEncodingContainer<K>.Key) throws
func encodeIfPresent(_ value: T?, forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes the given value for the given key if it is not nil.

  • parameter value: The value to encode.
  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeIfPresent<T>(_ value: T?, forKey key: KeyedEncodingContainer<K>.Key) throws where T: Encodable
func encodeIfPresent(_ value: Bool?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Bool?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: String?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: String?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Double?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Double?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Float?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Float?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Int?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Int?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Int8?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Int8?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Int16?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Int16?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Int32?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Int32?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: Int64?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: Int64?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: UInt?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: UInt?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: UInt8?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: UInt8?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: UInt16?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: UInt16?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: UInt32?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: UInt32?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: UInt64?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent(_ value: UInt64?, forKey key: Self.Key) throws
func encodeIfPresent(_ value: T?, forKey key: Self.Key) throws Required

Declaration

public mutating func encodeIfPresent<T>(_ value: T?, forKey key: Self.Key) throws where T: Encodable
func encodeNil(forKey key: KeyedEncodingContainer<K>.Key) throws Required

Encodes a null value for the given key.

  • parameter key: The key to associate the value with.

Declaration

public mutating func encodeNil(forKey key: KeyedEncodingContainer<K>.Key) throws
func nestedContainer(keyedBy keyType: NestedKey.Type, forKey key: KeyedEncodingContainer<K>.Key) -> KeyedEncodingContainer<NestedKey> Required

Stores a keyed encoding container for the given key and returns it.

  • parameter keyType: The key type to use for the container.
  • parameter key: The key to encode the container for.

Declaration

public mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type, forKey key: KeyedEncodingContainer<K>.Key) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey
func nestedUnkeyedContainer(forKey key: KeyedEncodingContainer<K>.Key) -> UnkeyedEncodingContainer Required

Stores an unkeyed encoding container for the given key and returns it.

  • parameter key: The key to encode the container for.

Declaration

public mutating func nestedUnkeyedContainer(forKey key: KeyedEncodingContainer<K>.Key) -> UnkeyedEncodingContainer
func superEncoder() -> Encoder Required

Stores a new nested container for the default super key and returns A new encoder instance for encoding super into that container.

Equivalent to calling superEncoder(forKey:) with Key(stringValue: "super", intValue: 0).

Declaration

public mutating func superEncoder() -> Encoder
func superEncoder(forKey key: KeyedEncodingContainer<K>.Key) -> Encoder Required

Stores a new nested container for the given key and returns A new encoder instance for encoding super into that container.

  • parameter key: The key to encode super for.

Declaration

public mutating func superEncoder(forKey key: KeyedEncodingContainer<K>.Key) -> Encoder