KeyedDecodingContainer

public extension KeyedDecodingContainer
  • Decodes a value of the given type for the given key if present and if not, returns the provided default value.

    Throws

    An Error if the decoding process encounters an error.

    Declaration

    Swift

    func decode<T>(forKey key: K, defaultValue: T) throws -> T
        where T: Decodable

    Parameters

    key

    The key that the decoded value is associated with.

    defaultValue

    The value to use if the key decoded is not present.

    Return Value

    A decoded value of the requested type, or the default value if the Decoder does not have an entry associated with the given key, or if the value is a null value.