URLDecoderProtocol

public protocol URLDecoderProtocol

A protocol for decoding URLCodable objects from a URL’s query parameters.

  • decode(type:from:decoder:) Default implementation

    Decodes a URLCodable object from the given URL using a provided JSONDecoder.

    Throws

    An error if decoding fails.

    Default Implementation

    Provides a default implementation that uses a JSONDecoder.

    Declaration

    Swift

    func decode<T: URLCodable>(
        type: T.Type,
        from url: URL,
        decoder: JSONDecoder
    ) throws -> T

    Parameters

    type

    The type conforming to URLCodable to decode.

    url

    The URL containing the query parameters for decoding.

    decoder

    The JSONDecoder used for decoding. Defaults to a new JSONDecoder if not provided.

    Return Value

    A decoded instance of the specified type.