KeyedDecodingContainer

extension KeyedDecodingContainer
  • Decodes a value of the given type for the given key.

    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

    Swift

    public func decode(_ type: [Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [Any]

    Parameters

    type

    The type of value to decode.

    key

    The key that the decoded value is associated with.

    Return Value

    A value of the requested type, if present for the given key and convertible to the requested type.

  • Decodes a value of the given type for the given key.

    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

    Swift

    public func decode(_ type: [String : Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [String : Any]

    Parameters

    type

    The type of value to decode.

    key

    The key that the decoded value is associated with.

    Return Value

    A value of the requested type, if present for the given key and convertible to the requested type.

  • 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.

    Throws

    DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type.

    Declaration

    Swift

    public func decodeIfPresent(_ type: [Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [Any]?

    Parameters

    type

    The type of value to decode.

    key

    The key that the decoded value is associated with.

    Return Value

    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.

  • 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.

    Throws

    DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type.

    Declaration

    Swift

    public func decodeIfPresent(_ type: [String : Any].Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> [String : Any]?

    Parameters

    type

    The type of value to decode.

    key

    The key that the decoded value is associated with.

    Return Value

    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.