struct KeyedEncodingContainer<K>
Inheritance |
KeyedEncodingContainerProtocol
View Protocol Hierarchy →
|
---|---|
Associated Types | |
Import | import Swift |
Initializers
Creates a new instance with the given container.
container
: The container to hold.
Declaration
init<Container>(_ container: Container)
Instance Variables
The path of coding keys taken to get to this point in encoding.
Declaration
var codingPath: [CodingKey] { get }
Instance Methods
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
Declared In
KeyedEncodingContainer
, KeyedEncodingContainerProtocol
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: KeyedEncodingContainer<K>.Key) throws
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: KeyedEncodingContainer<K>.Key) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey
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 nestedUnkeyedContainer(forKey key: KeyedEncodingContainer<K>.Key) -> UnkeyedEncodingContainer
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
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: KeyedEncodingContainer<K>.Key) -> Encoder
A concrete container that provides a view into an encoder's storage, making the encoded properties of an encodable type accessible by keys.