KeyedDecodingContainer

public extension KeyedDecodingContainer

KeyedDecodingContainer+Decodable adds the ability to decode an array

Author

Adamas

Version

1.6.0

Date

30/03/2019
  • Decode an array if presented

    Throws

    DecodingError.typeMismatch if the encountered stored value is not an unkeyed container or a contained object doesn’t match the object type.

    Throws

    DecodingError.valueNotFound if the encountered encoded value is null, or of there are no more values to decode.

    Declaration

    Swift

    func decodeArrayIfPresent<O>(for key: K) throws -> [O]? where O : Decodable

    Parameters

    key

    The coding key

    Return Value

    An array of objects

  • Decode an array

    Throws

    DecodingError.typeMismatch if the encountered stored value is not an unkeyed container or a contained object doesn’t match the object type.

    Throws

    DecodingError.valueNotFound if the encountered encoded value is null, or of there are no more values to decode.

    Declaration

    Swift

    func decodeArray<O>(for key: K) throws -> [O] where O : Decodable

    Parameters

    key

    The coding key

    Return Value

    An array of objects

  • Decode an optional value or object

    Throws

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

    Declaration

    Swift

    func decodeIfPresent<O>(for key: K) throws -> O? where O : Decodable

    Parameters

    key

    The coding key

    Return Value

    The value or object

  • Decode a value or object

    Throws

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

    Declaration

    Swift

    func decode<O>(for key: K) throws -> O where O : Decodable

    Parameters

    key

    The coding key

    Return Value

    The value or object