KeyedEncodingContainerProtocol

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.

Encoders should provide types conforming to KeyedEncodingContainerProtocol for their format.

Inheritance View Protocol Hierarchy →
Associated Types
Import
  • import Swift

Instance Variables

var codingPath: [CodingKey] Required

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

Declaration

Instance Methods

mutating func encode(_: Bool, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Bool, forKey key: Self.Key) throws
mutating func encode(_: Double, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Double, forKey key: Self.Key) throws
mutating func encode(_: Float, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Float, forKey key: Self.Key) throws
mutating func encode(_: Int, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Int, forKey key: Self.Key) throws
mutating func encode(_: Int8, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Int8, forKey key: Self.Key) throws
mutating func encode(_: Int16, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Int16, forKey key: Self.Key) throws
mutating func encode(_: Int32, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Int32, forKey key: Self.Key) throws
mutating func encode(_: Int64, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: Int64, forKey key: Self.Key) throws
mutating func encode(_: String, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: String, forKey key: Self.Key) throws
mutating func encode(_: UInt, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: UInt, forKey key: Self.Key) throws
mutating func encode(_: UInt8, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: UInt8, forKey key: Self.Key) throws
mutating func encode(_: UInt16, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: UInt16, forKey key: Self.Key) throws
mutating func encode(_: UInt32, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: UInt32, forKey key: Self.Key) throws
mutating func encode(_: UInt64, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode(_ value: UInt64, forKey key: Self.Key) throws
mutating func encode<T>(_: T, forKey: Self.Key) Required

Encodes the given value for the given key.

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encode<T>(_ value: T, forKey key: Self.Key) throws
mutating func encodeConditional(_:forKey:)

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.

object: The object to encode.

key: The key to associate the object with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeConditional<T>(_ object: T, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: Bool?, forKey: Self.Key)

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeIfPresent(_ value: Bool?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: Double?, forKey: Self.Key)

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeIfPresent(_ value: Int64?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: String?, forKey: Self.Key)

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeIfPresent(_ value: String?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: UInt?, forKey: Self.Key)

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

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

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeIfPresent(_ value: UInt64?, forKey key: Self.Key) throws
mutating func encodeIfPresent<T>(_: T?, forKey: Self.Key)

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

value: The value to encode.

key: The key to associate the value with. throws: EncodingError.invalidValue if the given value is invalid in the current context for this format.

Declaration

  • mutating func encodeIfPresent<T>(_ value: T?, forKey key: Self.Key) throws
mutating func encodeNil(forKey:) Required

Encodes a null value for the given key.

key: The key to associate the value with. throws: EncodingError.invalidValue if a null value is invalid in the current context for this format.

Declaration

  • mutating func encodeNil(forKey key: Self.Key) throws
mutating func nestedContainer(keyedBy:forKey:) Required

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

keyType: The key type to use for the container.

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

Declaration

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

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

key: The key to encode the container for. returns: A new unkeyed encoding container.

Declaration

mutating func superEncoder() 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).

returns: A new encoder to pass to super.encode(to:).

Declaration

  • mutating func superEncoder() -> Encoder
mutating func superEncoder(forKey:) Required

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

key: The key to encode super for. returns: A new encoder to pass to super.encode(to:).

Declaration

  • mutating func superEncoder(forKey key: Self.Key) -> Encoder

Default Implementations

mutating func encodeConditional(_:forKey:)

Declaration

  • mutating func encodeConditional<T>(_ object: T, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: Bool?, forKey: Self.Key)

Declaration

  • mutating func encodeIfPresent(_ value: Bool?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: Double?, forKey: Self.Key)

Declaration

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

Declaration

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

Declaration

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

Declaration

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

Declaration

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

Declaration

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

Declaration

  • mutating func encodeIfPresent(_ value: Int64?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: String?, forKey: Self.Key)

Declaration

  • mutating func encodeIfPresent(_ value: String?, forKey key: Self.Key) throws
mutating func encodeIfPresent(_: UInt?, forKey: Self.Key)

Declaration

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

Declaration

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

Declaration

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

Declaration

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

Declaration

  • mutating func encodeIfPresent(_ value: UInt64?, forKey key: Self.Key) throws
mutating func encodeIfPresent<T>(_: T?, forKey: Self.Key)

Declaration

  • mutating func encodeIfPresent<T>(_ value: T?, forKey key: Self.Key) throws