URLDecoder

public final class URLDecoder : URLDecoderProtocol

A class for universally decoding Codable objects from a URL’s query parameters.

  • Initializes a new instance of URLDecoder.

    Declaration

    Swift

    public init()
  • Decodes a Codable object from the given URL’s query parameters.

    Throws

    Throws an error if decoding fails.

    Declaration

    Swift

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

    decoder

    The JSONDecoder used for decoding (defaults to JSONDecoder).

    Return Value

    A decoded instance of the specified type.