struct KeyedDecodingContainer<K> A concrete container that provides a view into a decoder's storage, making the encoded properties of a decodable type accessible by keys. Inheritance KeyedDecodingContainerProtocol View Protocol Hierarchy → Associated Types Key = K Import import Swift Initializers init(_:) Creates a new instance with the given container. container: The container to hold. Declaration init<Container>(_ container: Container) Instance Variables var allKeys: [K] All the keys the decoder has for this container. Different keyed containers from the same decoder may return different keys here, because it is possible to encode with multiple key types which are not convertible to one another. This should report all keys present which are convertible to the requested type. Declaration var allKeys: [K] { get } var codingPath: [CodingKey] The path of coding keys taken to get to this point in decoding. Declaration var codingPath: [CodingKey] { get } Instance Methods func contains(_:) Returns a Boolean value indicating whether the decoder contains a value associated with the given key. The value associated with the given key may be a null value as appropriate for the data format. key: The key to search for. returns: Whether the Decoder has an entry for the given key. Declaration func contains(_ key: KeyedDecodingContainer<K>.Key) -> Bool func decode(_: Bool.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Bool.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Bool func decode(_: Double.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Double.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Double func decode(_: Float.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Float.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Float func decode(_: Int.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Int.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int func decode(_: Int8.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Int8.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int8 func decode(_: Int16.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Int16.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int16 func decode(_: Int32.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Int32.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int32 func decode(_: Int64.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: Int64.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int64 func decode(_: String.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: String.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> String func decode(_: UInt.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: UInt.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt func decode(_: UInt8.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: UInt8.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt8 func decode(_: UInt16.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: UInt16.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt16 func decode(_: UInt32.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: UInt32.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt32 func decode(_: UInt64.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode(_ type: UInt64.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt64 func decode<T>(_: T.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A value of the requested type, if present for the given key and convertible to the requested type. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func decode<T>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> T where T : Decodable func decodeIfPresent(_: Bool.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Bool.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Bool? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Double.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Double.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Double? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Float.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Float.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Float? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Int.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Int.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Int8.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Int8.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int8? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Int16.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Int16.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int16? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Int32.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Int32.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int32? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: Int64.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: Int64.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> Int64? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: String.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: String.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> String? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: UInt.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: UInt.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: UInt8.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: UInt8.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt8? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: UInt16.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: UInt16.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt16? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: UInt32.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: UInt32.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt32? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent(_: UInt64.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent(_ type: UInt64.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> UInt64? Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeIfPresent<T>(_: T.Type, forKey: KeyedDecodingContainer<K>.Key) Decodes a value of the given type for the given key, if present. This method returns nil if the container does not have a value associated with key, or if the value is null. The difference between these states can be distinguished with a contains(_:) call. type: The type of value to decode. key: The key that the decoded value is associated with. returns: A decoded value of the requested type, or nil if the Decoder does not have an entry associated with the given key, or if the value is a null value. throws: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. Declaration func decodeIfPresent<T>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> T? where T : Decodable Declared In KeyedDecodingContainer, KeyedDecodingContainerProtocol func decodeNil(forKey:) Decodes a null value for the given key. key: The key that the decoded value is associated with. returns: Whether the encountered value was null. throws: DecodingError.keyNotFound if self does not have an entry for the given key. Declaration func decodeNil(forKey key: KeyedDecodingContainer<K>.Key) throws -> Bool func nestedContainer(keyedBy:forKey:) Returns the data stored for the given key as represented in a container keyed by the given key type. type: The key type to use for the container. key: The key that the nested container is associated with. returns: A keyed decoding container view into self. throws: DecodingError.typeMismatch if the encountered stored value is not a keyed container. Declaration func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey func nestedUnkeyedContainer(forKey:) Returns the data stored for the given key as represented in an unkeyed container. key: The key that the nested container is associated with. returns: An unkeyed decoding container view into self. throws: DecodingError.typeMismatch if the encountered stored value is not an unkeyed container. Declaration func nestedUnkeyedContainer(forKey key: KeyedDecodingContainer<K>.Key) throws -> UnkeyedDecodingContainer func superDecoder() Returns a Decoder instance for decoding super from the container associated with the default super key. Equivalent to calling superDecoder(forKey:) with Key(stringValue: "super", intValue: 0). throws: DecodingError.keyNotFound if self does not have an entry for the default super key. throws: DecodingError.valueNotFound if self has a null entry for the default super key. Declaration func superDecoder() throws -> Decoder func superDecoder(forKey:) Returns a Decoder instance for decoding super from the container associated with the given key. key: The key to decode super for. returns: A new Decoder to pass to super.init(from:). throws: DecodingError.keyNotFound if self does not have an entry for the given key. throws: DecodingError.valueNotFound if self has a null entry for the given key. Declaration func superDecoder(forKey key: KeyedDecodingContainer<K>.Key) throws -> Decoder