HADecodeTransformable

public protocol HADecodeTransformable

Decode a value by massagging into another type

For example, this allows decoding a Date from a String without having to do intermediate casting in calling code.

  • Convert some value to the expected value

    Throws

    If the value contained errors preventing transform

    Declaration

    Swift

    static func decode(unknown value: Any) throws -> Self?

    Parameters

    value

    The value to decode

    Return Value

    An instance from value – nil allowed

Available where Self: RawRepresentable

  • decode(unknown:) Default implementation

    Default Implementation

    Converts from an unknown value to this raw representable type

    Declaration

    Swift

    static func decode(unknown value: Any) -> Self?

    Parameters

    value

    The value to attempt to convert

    Return Value

    The value transformed, if it is of the right type and init succeeds