AnyDecoder

public protocol AnyDecoder

A decoder type.

Swift has no common built-in protocol for all decoder types. This protocol remedies that shortcoming. Furthermore, it enables type inference-based API support for decoder tpes conforming to the AnyDecoder protocol.

  • Returns a type-inferred value, decoded from a Data object using decoder conforming to the AnyDecoder protocol.

    If the Data object is not syntacticlly valid, this generic instance method throws the DecodingError.dataCorrupted(_:) error. If a value within this object fails to decode, this method throws the corresponding error.

    Declaration

    Swift

    func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable

    Parameters

    type

    The type, adopting the Decodable protocol, of the value to decode from the supplied Data object.

    data

    The Data object to decode.

    Return Value

    A decoded object adopting the Decodable protocol.